Add autowiring for laravel container #46638
Unanswered
asanikovich
asked this question in
Ideas
Replies: 1 comment
-
Personally I'm not a fun of such magic behavior. In my opinion interface should be explicitly bind to implementation. I don't like MailSender from some third party package would be called just because it exists and I miss to bind interface MailSenderInterface to some RiseAnErrorSender. I'd riser get an instantiation error on resolving MailSenderInterface and choose appropriate implementation by my self. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Based on symfony container autowiring https://symfony.com/doc/current/service_container/autowiring.html#working-with-interfaces I want to offer to add autowiring for laravel container.
Example:
We have Interface
And implementation
Usage in code
If we try to run now, we will have the error:
To fix it we need bind interface with class explicitly.
When autowiring is enabled and if only one class exists that implements an interface, we can automatically create bind them:
for any usage of TransformerInterface provide Rot13Transformer.
What do you think, community?
Beta Was this translation helpful? Give feedback.
All reactions