Bug #96370
closed@TYPO3\CMS\Extbase\Annotation\Inject not working with Services.yaml in TYPO3 10.4.21
0%
Description
Hi, when I register a service through Services.yaml the dependency injection with @TYPO3\CMS\Extbase\Annotation\Inject in my controllers aren't working anymore.
I have removed and changed parts of the Services.yaml and figured out that the namespace to Classes folder configuration causes this error.
Removing this configuration snippet results in working dependency injection:
Vendor\Namespace\:
resource: '../Classes/*'
So I guess there is a bug leading to this.
For now I got the workaround by injecting the needed classes with inject methods, but this should work anyway
Updated by Simon Schaufelberger almost 3 years ago
Best practice is either inject Methods or Constructor injection.
Updated by Benjamin Franzke almost 3 years ago
- Status changed from New to Rejected
That is true, TYPO3\CMS\Extbase\Annotation\Inject
is not supported for Symfony DI based dependency injection.
Therefore Symfony DI is opt-in via Services.yaml.
If you disabled injection via Services.yaml, the extbase objectmananger is used instead (legacy mode).
You need to migrate to constructor or injectMethod() injection, which are supported in Symfony DI mode.
Note: This will also help with upgraded to v12, as https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-96107-DeprecatedFunctionalityRemoved.html#description