All i needed was in the configure()
method of the WebCoreModule
following line:
requestStaticInjection(ClassThatIsUsingInjectedMember.class);
Question
I am a new to Guice dependecy injection, hope someone could explain me why my code doesn't work.
here is the class that extends AbstractModule:
public class WebCoreModule extends AbstractModule {
@Provides
public SomeFactory getSomeFactory() {
return new SomeFactoryImpl();
}
}
and in the other class i have a private member
private static @Inject SomeFactory factory;
I'd like to invoke methods on factory
object, but it is always null. Also I set a breakpoint on getSomeFactory()
method and it is never being invoked.
What am I doing wrong?
Solution
All i needed was in the configure()
method of the WebCoreModule
following line:
requestStaticInjection(ClassThatIsUsingInjectedMember.class);