-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Always autowire the constructor #21306
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
Conversation
618e2fe
to
3dc98ce
Compare
3dc98ce
to
be3d11f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Looks like a slippery slope here :) What if my config is: services:
Foo\Bar: { autowire: ['setLogger'] } |
The constructor will be autowired if it exists. If it's not wanted, it's weird to use |
I agree with @dunglas: autowiring has to wire the constructor - and optionally the setters. services:
Foo\Bar: { autowire: ['__construct', 'setLogger'] } looks like unneeded boilerplate to me, that people will forget most of the time. There is always a constructor to wire. We don't need to handle the case for one wanting to autowire the setters but wire manually the contructor, because by doing so, one already went out of autowire-land. |
Thank you @dunglas. |
…(dunglas) This PR was merged into the 3.3-dev branch. Discussion ---------- [DependencyInjection] Always autowire the constructor | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no (because method autowiring has been introduced in 3.3) | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Always try to autowire the constructor even if it has not been configured explicitly. It doesn't make sense to autowire some methods but not the constructor. It will also allow to write shorter definitions when using method autowiring: ```yaml services: Foo\Bar: { autowire: ['set*'] } ``` instead of ```yaml services: Foo\Bar: { autowire: ['__construct', 'set*'] } ``` Commits ------- be3d11f [DependencyInjection] Always autowire the constructor
Always try to autowire the constructor even if it has not been configured explicitly. It doesn't make sense to autowire some methods but not the constructor. It will also allow to write shorter definitions when using method autowiring:
instead of