I have a simple injection module:
public class InjectionModule extends AbstractModule { @Override protected void configure() { bind(SomeModel.class); bind(SomeData.class); } }
it is included in my application.conf application
play { modules { enabled += "com.example.InjectionModule" } }
In my controller, I want to create a new model, and I do like this:
public Promise<Result> getPage() { return handleRequest(() -> Play.application().injector().instanceOf(SomeModel.class)); }
handleRequest() simply making a promise and calling process() in the model.
In my SomeModel class SomeModel I am trying to introduce some dependencies, but they are always zero, which I do:
@Inject private SomeData data; void process() {
but data always null.
Note that if I just use new SomeData() , then it works.
Update
I modified it to use constructor injection and it all works great, why doesn't my field injection work?
source share