[TYPO3-mvc] Dependency Injection in DomainObjectInterface

Pascal Jungblut mail at pascal-jungblut.com
Tue Dec 7 03:38:50 CET 2010


Hi Sebastian,

On 06.12.2010, at 19:24, Sebastian Kurfürst wrote:
>> 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.

I opened a bug report for that [1] and I think that it could be solved quite trivial by replacing "new $className" with ObjectManager->create().

> 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.

I moved the unserialize() call to the object-container and wrapped it into a function "getEmptyObject". That way, dependencies get injected into the reconstituted object. Maybe someone[tm] might have a look at it (or should I start an RFC directly?). 

> Well, you can get the ObjectManager with
> t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager'); -- and then
> use the ...->get(..) method on the Object Manager.

Oh, that was too simple :-) Tested it and works fine, thanks!

Regards
Pascal

[1] <http://forge.typo3.org/issues/11311>


More information about the TYPO3-project-typo3v4mvc mailing list