Architecture and request · Question 1 of 12
Which form of dependency injection does TYPO3 recommend for your own services?
1 answer is correct. Easy
Show answer
Answer
- C Constructor injection: dependencies are declared as constructor parameters
Explanation
TYPO3 uses the Symfony service container, which detects dependencies automatically (autowiring) and passes them in when a service is created. Constructor injection is recommended, for example public function __construct(private readonly ProductRepository $productRepository) {}: the class shows at a glance what it needs and can easily be given test doubles in tests. inject*() methods are only intended for abstract base classes whose constructor should not burden subclasses. GeneralUtility::makeInstance() hides dependencies inside the code and is only the exception for services nowadays.