typo3extbase

How does constructor injection work in TYPO3 Extbase?


I just realized that TYPO3 Extbase can (in some situations?) inject dependencies even if you do not pass them to the constructor when you call e.g. $objectManager->get(Foo::class)? I am confused how and when this works. I could not find the answer myself by reading the source code.


Solution

  • Have a look at \TYPO3\CMS\Extbase\Object\Container\Container::getConstructorArguments().

    It works as follows:

    if

    then this class will be instantiated and supplied as a parameter to the constructor call