[TYPO3-mvc] RFC #9062: prepare objectManager to become the central factory
Bastian Waidelich
bastian at typo3.org
Wed Jul 28 09:46:39 CEST 2010
Felix Oertel wrote:
Hi Felix,
> As we want to have dependency injection (later on) and stay in sync with
> FLOW3 (at least as far as possible and useful), I think it is important
> to let the ObjectManager become the central place to handle our objects.
I fully agree with that. But to be honest, I'm not convinced by the
static solution. Even if it is possible to mock static methods with
PHPUnit 3.5, we should try to avoid static methods as much as possible
as it's a sign for inflexible architecture - not only, because its not
(easily) testable. So for now, I'd vote with -1 (sorry).
In order to avoid this and to get in sync with FLOW3, I'd suggest
following solution:
Before the ObjectManager returns an object it calls the
"injectObjectManager()" method on it (if it exists).
So you could use it like:
/**
* @var Tx_Extbase_Object_ObjectManagerInterface
*/
var $objectManager;
public function
injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface
$objectManager) {
$this->objectManager = $objectManager;
}
As most of the abstract core classes will already implement this method,
you mostly won't have to care about it.
In a next step the ObjectManager could call all inject*() methods (maybe
based on a TS configuration)
What do you think about this solution?
BTW: Tx_Extbase_Object_Manager should be renamed to
Tx_Extbase_Object_ObjectManager
Greetings from Cologne,
Bastian
More information about the TYPO3-project-typo3v4mvc
mailing list