-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency Injection does not work when constructor parameters are given #5118
Comments
In docs for TYPO3 12 I found following sentence:
I also don't understand why I should mark an object which is called with constructor arguments should be marked |
The problem is known and described in one changelog entry:
|
You can actually use constructor arguments with DI. Symfony services.yaml allows you to define constructor arguments (using "bind" or "arguments"). |
But no dynamic ones. |
Sure. But we need to have an adjustment that takes this into account. I would suggest to add a sentence to https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/DependencyInjection/Index.html#arguments along these lines: "If you use GU::makeInstance() on any class that has custom constructor arguments (apart from DI) you must specify all parameters on your own, because no automatism can be applied. (Insert example of GU::mI() that would fail and show passing all arguments, or recommending to not use constructor based special parameters but instead setters()/variable injection so that constructors are purely used for DI, or to advise not using GU:mI at all and using Services.yaml wiring like above. Or purely using constructor for arguments and make the whole class uses method injection.) Note that if you use classes with custom constructor arguments with regular DI configration, you can pass/bind arguments to the constructor call via the Services.yaml registration, as seen in the example above. (Sidenote: thumbs-downing a valid note from someone who's trying to help isn't really motivating.) |
Current behavior
The "Dependency Injection" page does not mention the fact that DI is not applied when constructor parameters are given.
https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/DependencyInjection/Index.html#method-injection
Method injection is something that could still work when
GeneralUtility::makeInstance()
is called with constructor parameters, but DI is only applied when no parameters are given.Expected behavior/output
The DI documentation should describe that classes with constructor parameters cannot be used for DI at all.
Links
TYPO3 versions
11, 12, 13
The text was updated successfully, but these errors were encountered: