guice

In a project that uses a DI framework, should you NEVER use the 'new' operator?

I'm trying to wrap my head around Dependency Injection. One of the things I'm confused about is whether all of your object instantiation needs to be controlled by the DI framework (Spring, Guice, etc). Or, if not, how do you determine which objects are instantiated by the framework and which objects are instantiated with the new oper...

Injecting generics with Guice

I am trying to migrate a small project, replacing some factories with Guice (it is my first Guice trial). However, I am stuck when trying to inject generics. I managed to extract a small toy example with two classes and a module: import com.google.inject.Inject; public class Console<T> { private final StringOutput<T> out; @Inject ...

Java package scanner - find all classes with a given interface

In C# you can easily read all classes from a given assembly. I'm looking for equivalent feature in Java. I need this to automatically bind EJB beans to my Guice Module. ...

Guice + Quartz + iBatis

I'm trying to wire together Guice (Java), Quartz scheduler and iBatis (iBaGuice) to do the following: Start command line utility-scanner using main() Periodically scan directory (provided as argument) for files containing formatted output (XML or YAML) When file is detected, parse and output result to the database The problems: I u...

How do I get google guice to inject a custom logger, say a commons-logging or log4j logger

Google guice has a built-in logger binding (http://code.google.com/p/google-guice/wiki/BuiltInBindings). But what if I want to use a commons-logging or log4j logger? Can I get guice to inject a Log created by LogFactory.getLog(CLASS.class) But having the same behavior as in built-in binding: The binding automatically sets the log...

Properties framework in java apps

Hi All I have been using spring for a while as my IOC. It has also a very nice way of injecting properties in your beans. Now I am participating in a new project where the IOC is Guice. I dont understand fully the concept how should I inject properties in to my beans using Guice. The question : Is it actually possible to inject raw p...

How to use Guice in Swing application

I have a Swing application that I would like to convert from spaghetti to using dependency injection with Guice. Using Guice to provide services like configuration and task queues is going great but I'm now starting on the GUI of the app and am unsure of how to proceed. The application is basically a JFrame with a bunch of tabs in a JTa...

How do I write a Guice Provider that doesn't explicitly create objects?

Say I have a ClassWithManyDependencies. I want to write a Guice Provider for this class, in order to create a fresh instance of the class several times in my program (another class will depend on this Provider and use it at several points to create new instances). One way to achieve this is by having the Provider depend on all the depen...

Gin / Gwt / Eclipse: com.google.gwt.inject.Inject cannot be resolved to a type

I'm trying to use GIN (Guice for GWT) within eclipse. The tutorial says to add a line to my module xml file: <inherits name="com.google.gwt.inject.Inject"/> However, when I do this Eclipse reports an error "com.google.gwt.inject.Inject cannot be resolved to a type" I've added gin.jar, aopalliance.jar and guice.jar as referenced l...

Practical advice on using Jersey and Guice for RESTful service

From what I can find online, the state of the art for Guice + Jersey integration has stagnated since 2008 when it appears both teams reached an impasse. The crux of the issue is that JAX-RS annotations perform field and method injection and this doesn't play nicely with Guice's own dependency injection. A few examples which I've found d...

IoC problem with multi binding

I'm Java beginner and IoC as well. How to do stuff: public class Foo{ //private Bar bar; //Bar is an interface private int var; public Foo(){ } public void setVar(int var){ this.var = var;} public Bar getBar(){ if(var==1){ return new BarImpl1(); //an implemantation of Bar interface } else if(var==2){ return new BarImpl2(); //an imp...

Hidden Features of Google Guice

Google Guice provides some great dependency injection features. I came across the @Nullable feature recently which allows you to mark constructor arguments as optional (permitting null) since Guice does not permit these by default: e.g. public Person(String firstName, String lastName, @Nullable Phone phone) { this.firstName = che...

Guice creates Swing components outside of UI thread problem?

I'm working on Java Swing application with Google Guice as an IOC container. Things are working pretty well. There are some UI problems. When a standard L&F is replaced with Pushing pixels Substance L&F application is not running due to Guice's Swing components creation outside of UI thread. Is there a way to tell Guice to create Swing ...

Guice and GWT problem - can't find GWT.rpc

Hi! I build a simple contact manager app with simple service and it did work. Then I decided I want to use Guice for managing my services and implementations. I also use mvp4g plugin for MVP design pattern. I followed the exmaple of Eric Burke on his blog, and my code looks like that: ContactService.java @RemoteServiceRelativePath("GWT....

How do I apply a servlet filter when serving an HTML page directly?

First off, I'm using Google AppEngine and Guice, but I suspect my problem is not related to these. When the user connect to my (GWT) webapp, the URL is a direct html page. For example, in development mode, it is: http://127.0.0.1:8888/Puzzlebazar.html?gwt.codesvr=127.0.0.1:9997. Now, I setup my web.xml in the following way: <?xml versi...

setter injection guice + wicket

Hi, I have a Wicket Web Page where I create a new Object of class A: A a = new A(User u); In A I would like to have setter injection, however this is actually not done. I have heard that one must provide an empty constructor but how is it possible to have also a non - empty constructor with setter injection? ...

Guice Problem with Tests

Hey I wrote a LudoGame and now I like to test it with a little GuiceInjection^^ I have an Interface IDie for my die. Now for the game I only need an IDie instead of a realdie => in tests I simply give the LudoGame a MokeDie to set up the Numbers I like to roll. The IDie has only one method: roll() which returns a int. BUT the mokeDie now...

What is your alternative to annotations?

Let us say Java didn't have annotations. What would be the ideas you would come up with to design something like Google Guice's DI framework? I am fairly new to Java and cannot think of anything other than what Junit3 Had XML Configuration Some kind of introspection? How would you inspect the elements that needed to be injected? Wha...

Guice expert question

Hi All I am wondering if someone would be such an expert in guice that he even would know how to implement that : I have an injection annotation (@ConfParam)with some parameters , like that : class TestClass { private final int intValue; @Inject public TestClass(@ConfParam(section = "test1", key = "1") int intValue{ ...

How do I bind Different Interfaces using Google Guice?

Do I need to create a new module with the Interface bound to a different implementation? Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl.class); } }).getInstance(Chef.class); Chef ...