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?

Était-ce utile?

La solution

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

requestStaticInjection(ClassThatIsUsingInjectedMember.class);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top