[TYPO3-mvc] Dependency Injection in DomainObjectInterface

Sebastian Kurfürst sebastian at typo3.org
Mon Dec 6 19:24:40 CET 2010


Hey Pascal,

Am 06.12.10 19:09, schrieb Pascal Jungblut:
> Hey guys,
> 
> I was just wondering how you'd use dependency injection in domain objects? As transformToObject() uses "new $className;"
That's a bug, I think -- but I am not sure if we can change this.

The issue is that when an object is *reconstituted from database*, the
constructor is not called, and we would need to re-inject dependencies
-- and that won't be easily supported in Extbase. So the best
quick-n-dirty fix is to use the method described below.

> to create domain objects, DI is not possible and it might not be needed for the vast majority of people. 
> However, I'm using the observer-pattern on my domain objects to
notifiy tx_enetcache when they change.
> For that it would be really great if I could somehow inject either the
CacheObserver directly or the ObjectManager
> into the entity. How can I do that?
Well, you can get the ObjectManager with
t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager'); -- and then
use the ...->get(..) method on the Object Manager.

Greets,
Sebastian


More information about the TYPO3-project-typo3v4mvc mailing list