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?

Was it helpful?

Solution

All i needed was in the configure() method of the WebCoreModule following line:

requestStaticInjection(ClassThatIsUsingInjectedMember.class);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top