Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
618e2fe to3dc98ceCompare3dc98ce tobe3d11fCompare
nicolas-grekas left a comment
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.
👍
fabpot commentedJan 16, 2017
Looks like a slippery slope here :) What if my config is: services: Foo\Bar: { autowire: ['setLogger'] } |
dunglas commentedJan 16, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The constructor will be autowired if it exists. If it's not wanted, it's weird to use |
nicolas-grekas commentedJan 16, 2017
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. |
fabpot commentedJan 16, 2017
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/aAlways 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:```yamlservices: Foo\Bar: { autowire: ['set*'] }```instead of```yamlservices: Foo\Bar: { autowire: ['__construct', 'set*'] }```Commits-------be3d11f [DependencyInjection] Always autowire the constructor
Uh oh!
There was an error while loading.Please reload this page.
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