Heya, First of all, please DON'T do this. Keep your entities small and push/pull them from your services. Injecting dependencies is something really active-recordish and you don't want to know the tons of problems you run into with that.
Anyway, the simplest way is exactly to use postLoad, and then attach your own listener that injects the dependencies (Zend\Di may be useful in this case, but maybe a bit slow for you). I may also point out that having the service locator everywhere is just wrong and brings to really untestable code (mocking becomes really a problem). Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 12 November 2012 08:23, Griesi <ebert.ch...@gmail.com> wrote: > Hi, > > > > I am using Doctrine 2 in a Zend Framework 2 application. Is there any way > using ZF2 to inject dependencies into entities returned by Doctrine? > Entities are constructed by Doctrine when retrieved from the database. So > far as I know to inject dependencies in ZF2 I need to instantiate entities > using Service Locator. I cannot see how I can integrate that with Doctrine. > One Option might me Doctrine´s postLoad event. But I cannot see how I could > connect this with the Service Locator. I know how to make my entities > Service Locator aware. But this does not work when the entities are > returned > by Doctrine. The only feasible solution I can see right now is to write a > small service which takes the result returned from Doctrine and injects the > required dependencies. Is there a more elegant solution using Service > Locator directly, e.g. Service Locator aware entities? > > > > Best Regards > > Christian > >