-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Update autowiring.rst #10625
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
Update autowiring.rst #10625
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,6 +341,15 @@ Thanks to the ``App\Util\TransformerInterface`` alias, the autowiring subsystem | |
knows that the ``App\Util\Rot13Transformer`` service should be injected when | ||
dealing with the ``TransformerInterface``. | ||
|
||
.. tip:: | ||
|
||
As long as you have only one concrete implementation of an interface under the same | ||
namespace, alias is not mandatory and autowire will work injecting the concrete | ||
implementation even without alias definition. | ||
Nevertheless it is recommended to provide an alias in order to preserve application | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should drop this sentence. It may be confusing when reading the tip and the error should be clear especially given that we should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would point out somehow that, even if with a single concrete implementation it works, users should declare the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we really need to mention that explicitly. Do you think it adds more clarity (or eases some understanding)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, from one side you're right: we said previously that we need to alias interfaces and in the tip we say that for one single concrete instance, there's no need for alias, so there is a kind of "implicit" context create. BTW when writing this, I've noticed that, someone, if we suggest to declare explicitly an Maybe is safer to drop it and keep the "implicit" context as we cannot take into account an "unambiguous" choice/scenario? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand this part. Can you elaborate a bit more what you mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes of course. Hope to have been more precise this time 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand now. :) I agree with you. IIRC when there is more than one concrete implementation the DI component will already throw an exception that explains what needs to be changed anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes indeed. I will remove that part. Thanks for the feedback process. |
||
logic when a second concrete implementation kicks in, otherwise compiler compilation | ||
would throw an exception. | ||
|
||
Dealing with Multiple Implementations of the Same Type | ||
------------------------------------------------------ | ||
|
||
|
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.
I would reword this a bit:
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.
LGTM, I'm gonna change to suggested sentence.