Dependency Injection on model classes does not work
This may be by design - in which case the issue should be closed, and I should consider something else.
In other ORMs I have worked with, we used domain driven design, and as a consequence our model objects were allowed to be "thick". A further consequence of this is that we used dependency injection on the model objects to ensure they could delegate all relevant tasks to services etc.
It seems that any and all "@Inject" annotations on the model-classes are ignored when they are instantiated by EBeanORM using fx. Model.Finder<X,Y>.
Understanding that EBeanORM does not depend on a specific DI-framework, I realize that this may be why - but is there any way to intercept the instantiation of models. If this was possible I could at least ask Guice to inject using field/method injection after the model object was created, but before it was handed hydrated and handed over to the business logic/code.
Example of Constructor injection (which I don't think can work as EBean's enhancer breaks it):
public class MyModel extends Model {
@Inject
public MyModel(MyService service) {
this.service = service
}
}
Example of field injection (which can work if I can register something to be called after constructor is called, but before hydration and returning to the business logic/code):
public class MyModel extends Model {
@Inject
private MyService service;
}
Ideally, one could tell EBean which dependency injection framework is in play, and then it could combine the enhancement and DI such that it all just works :-)
Hello Oak, I've answerded your question here: https://groups.google.com/forum/#!topic/ebean/mSztuDQt0ck
FYI: Rob has a policy to ask questions always on the google group first: http://ebean-orm.github.io/support
cheers Roland
Closing.
As Roland has stated the policy is that we don't encourage questions on Github (as among other reasons this effectively spams those people watching this project). Please post questions to the google group first - thanks.
Cheers, Rob.