[TYPO3-mvc] DataMapper bypasses dependency injection in domain model object
Jan-Erik Revsbech
janerik at mocsystems.com
Tue Jan 25 09:09:53 CET 2011
Hi list, I'm currently trying out the new Extbase 1.3 bundled with TYPO3
4.5.
I'm especially trying out the new Dependency Injection (DI) things, but
have a problem. I have a domainmodel Tx_Mocshop_Domain_Model_Address
which has a injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface
$objectManager) methods. This works great if i create a new instance of
the model with
$objectManager->create("Tx_Mocshop_Domain_Model_Address"); then the
correct objectManager, is automatically injected into my address domain
model. However if I do a
$rep =
$objectManager->get("Tx_Mocshop_Domain_Repository_AddressRepository");
$address = $rep->findByUid(1);
The injectObjectManager methods on address object is not called.
I debugged it into the datamapper, in the mapSingleRow method. Here it
calls createEmptyObject which does a $object = unserialize('O:' .
strlen($className) . ':"' . $className . '":0:{};'); and thus bypasses
the objectmanager and the DI.
One solution would be to use $object =
$this->objectManager->create($className); Instead, but I guess that
would be quite a perfomance penalty. Another solution would be somehow
duplicate what the ObjectContainer does and inject needed classes into
the domain model.
Or is dependency injection in domain model just not supported currently?
Regards
Jan-Erik Revsbech
MOC Systems
More information about the TYPO3-project-typo3v4mvc
mailing list