Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged

Conversation

@dunglas
Copy link
Member

@dunglasdunglas commentedJan 16, 2017
edited
Loading

QA
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 ticketsn/a
LicenseMIT
Doc PRn/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:

services:Foo\Bar:{ autowire: ['set*'] }

instead of

services:Foo\Bar:{ autowire: ['__construct', 'set*'] }

jvasseur and skobkin reacted with confused emoji
@dunglasdunglasforce-pushed theautowiring_construct_default branch from3dc98ce tobe3d11fCompareJanuary 16, 2017 15:27
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍

@nicolas-grekasnicolas-grekas added this to the3.3 milestoneJan 16, 2017
@fabpot
Copy link
Member

Looks like a slippery slope here :)

What if my config is:

services:    Foo\Bar: { autowire: ['setLogger'] }

@dunglas
Copy link
MemberAuthor

dunglas commentedJan 16, 2017
edited
Loading

The constructor will be autowired if it exists. If it's not wanted, it's weird to useautowire instead of acall.

@nicolas-grekas
Copy link
Member

I agree with@dunglas: autowiring has to wire the constructor - and optionally the setters.
Having to state:

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
Copy link
Member

Thank you@dunglas.

@fabpotfabpot merged commitbe3d11f intosymfony:masterJan 16, 2017
fabpot added a commit that referenced this pull requestJan 16, 2017
…(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
@fabpotfabpot mentioned this pull requestMay 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@SimperfitSimperfitSimperfit approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

5 participants

@dunglas@fabpot@nicolas-grekas@Simperfit@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp