Skip to content

[Autowiring] - Rephrase aliasing when multiple classes with same interface #9755

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

Closed
wants to merge 2 commits into from
Closed

[Autowiring] - Rephrase aliasing when multiple classes with same interface #9755

wants to merge 2 commits into from

Conversation

Plopix
Copy link
Contributor

@Plopix Plopix commented May 10, 2018

This PR aims to enforce the "non-magic" aspect of the Autowiring.

Especially that sentence:
If you register this as a service, you now have two services that implement the App\Util\TransformerInterface type. Symfony doesn't know which one should be used for autowiring, so you need to choose one by creating an alias from the type to the correct service id (see Working with Interfaces).

This:
Symfony doesn't know which one should be used for autowiring
The more I read the more I think it is clear, but somehow It feels like, after one or two readings, you could understand that Symfony is somehow "choosing" by some sort of magic the service (i.e: Reflection for instance). Where it is definitely not and the "developer" must decide and tells the autowiring which one to use.

I think the current sentence is also clearer when you read all the documentation page where often (I guess) developers go straight to what they need and in this case "how to configure when you have an interface and multiple classes"

So I propose this change (which should not hurt) and open the discussion. Feel free to close if you think it is useless, I won't mind it did not take that long to do the PR ;)

@javiereguiluz javiereguiluz added this to the 3.4 milestone May 16, 2018
@javiereguiluz
Copy link
Member

Sébastien, thanks for this improvement. We merged it on 3.4 branch.

javiereguiluz added a commit that referenced this pull request May 16, 2018
…th same interface (Plopix, javiereguiluz)

This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes #9755).

Discussion
----------

[Autowiring] - Rephrase aliasing when multiple classes with same interface

This PR aims to enforce the "non-magic" aspect of the Autowiring.

Especially that sentence:
```If you register this as a service, you now have two services that implement the App\Util\TransformerInterface type. Symfony doesn't know which one should be used for autowiring, so you need to choose one by creating an alias from the type to the correct service id (see Working with Interfaces).```

This:
`Symfony doesn't know which one should be used for autowiring`
The more I read the more I think it is clear, but somehow It feels like, after one or two readings, you could understand that Symfony is somehow "choosing" by some sort of magic the service (i.e: Reflection for instance). Where it is definitely not and the "developer" *must decide* and tells the autowiring which one to use.

I think the current sentence is also clearer when you read all the documentation page where often (I guess) developers go straight to what they need and in this case "how to configure when you have an interface and multiple classes"

So I propose this change (which should not hurt) and open the discussion. Feel free to close if you think it is useless, I won't mind it did not take that long to do the PR ;)

Commits
-------

3165948 Fixed formatting
c89f73f Autowiring - Rephrase aliasing when multiple classes implement same interface
@Plopix Plopix deleted the autowiring-small-improvement branch May 16, 2018 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants