I have been using a ORM/ODM (morphia) for managing my models, but I'm running into an issue:
The constructor of a model is only called upon creation of the object (new MyObject(dep1, dep2)
), and is not called upon being loaded from db (db.get(id)
).
How does one inject non-serializable dependencies into an ORM-managed object?
I've been injecting dependencies directly into any methods that require it ie.
public void doSomething(UserDAO userDAO) { ... }
But this quickly leads to ugly code. Is there a better way?
Aucun commentaire:
Enregistrer un commentaire