Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DI] Deprecate autowiring-types in favor of aliases#21494
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
4366566 toc3e73dbCompareweaverryan commentedFeb 1, 2017
@nicolas-grekas Haha... I really like this simplification... but I don't understand how it works! :) Is there some significance to the service id matching the autowired interface? Otherwise... I would still expect that if I had 10 services for an interface (e.g. LoggerInterface)... that now it would simply appear that I would have11 services for that interface. Clearly, I'm missing something ;) |
nicolas-grekas commentedFeb 1, 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.
It is very simple: if there is a service named "Foo\BarInterface", then that's the one, when looking to wire a "Foo\BarInterface" type hint. |
UPGRADE-3.3.md Outdated
| DependencyInjection | ||
| ------------------- | ||
| * Autoriwing-types have been deprecated, use aliases instead. |
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.
Shouldn't we add an example here?
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.
indeed, the example from the pr desc fi
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.
example added
stof commentedFeb 1, 2017
this is a very elegant solution to the problem, allowing to use third-party services to autowire a type (as your alias can point to any service), and forbidding to explicitly configure the same autowired type twice for different services (as service ids are unique). So 👍 for me. |
c3e73db to78c9141Comparechalasr commentedFeb 1, 2017
Far simpler 👍 |
dunglas commentedFeb 1, 2017
Great! 👍 |
weaverryan commentedFeb 1, 2017
Ha, I missed the change to 👍 |
| $definition =$container->findDefinition('templating'); | ||
| $definition->setAutowiringTypes(array(ComponentEngineInterface::class,FrameworkBundleEngineInterface::class)); | ||
| $container->setAlias(ComponentEngineInterface::class,'templating'); | ||
| $container->setAlias(FrameworkBundleEngineInterface::class,'templating'); |
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.
this should be private aliases. We don't want to keep these service names in the compiled container
| <autowiring-type>Symfony\Component\EventDispatcher\EventDispatcher</autowiring-type> | ||
| </service> | ||
| <serviceid="Symfony\Component\EventDispatcher\EventDispatcherInterface"alias="event_dispatcher" /> | ||
| <serviceid="Symfony\Component\EventDispatcher\EventDispatcher"alias="event_dispatcher" /> |
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.
these should be private aliases
| <autowiring-type>Symfony\Component\DependencyInjection\ContainerInterface</autowiring-type> | ||
| <autowiring-type>Symfony\Component\DependencyInjection\Container</autowiring-type> | ||
| </service> | ||
| <serviceid="service_container"synthetic="true" /> |
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.
shouldn't this one be removed entirely ? The component already handles it
| </service> | ||
| <serviceid="service_container"synthetic="true" /> | ||
| <serviceid="Symfony\Component\DependencyInjection\ContainerInterface"alias="service_container" /> | ||
| <serviceid="Symfony\Component\DependencyInjection\Container"alias="service_container" /> |
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.
these aliases should be private
| <autowiring-type>Symfony\Component\Translation\TranslatorInterface</autowiring-type> | ||
| </service> | ||
| <serviceid="Symfony\Component\Translation\TranslatorInterface"alias="translator.default" /> |
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.
the alias should betranslator IMO instead, so that autowiring injects the real translator when using decoration. Otherwise, we loose the profiler integration when using autowiring and someone decorates the maintranslator alias rather than the private service.
And this alias should also be private (as any alias created purely for autowiring purpose anyway)
UPGRADE-3.3.md Outdated
| DependencyInjection | ||
| ------------------- | ||
| * Autoriwing-types have been deprecated, use aliases instead. |
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.
typo here
UPGRADE-4.0.md Outdated
| DependencyInjection | ||
| ------------------- | ||
| * Autoriwing-types have been removed, use aliases instead. |
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.
typo here
78c9141 tob11d391Comparenicolas-grekas commentedFeb 1, 2017
@stof comments addressed, thanks |
stof commentedFeb 1, 2017
btw, my comment about using private aliases for this is also true for the documentation when writing it |
weaverryan commentedFeb 1, 2017
Docs issue created - I added a note on there about your (Stof) "private aliases" comment. |
fabpot commentedFeb 1, 2017
Thank you@nicolas-grekas. |
…icolas-grekas)This PR was merged into the 3.3-dev branch.Discussion----------[DI] Deprecate autowiring-types in favor of aliases| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | yes| Tests pass? | yes| Fixed tickets |#21351,#19970, ~~#18040~~, ~~#17783~~| License | MIT| Doc PR |symfony/symfony-docs#7445https://github.com/symfony/symfony/pull/21494/files?w=1This PR deprecates autowiring-types and replaces them by plain aliases.ping@dunglas@weaverryanEg instead of```xml<service public="false"> <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type></service>```just do:```xml<service public="false" /><service alias="annotations.reader" public="false" />```Commits-------b11d391 [DI] Deprecate autowiring-types in favor of aliases
theofidry commentedFeb 1, 2017
@nicolas-grekas shouldn't this be back-ported to 2.8? Autowiring has been introduced there and IIRC there is |
chalasr commentedFeb 1, 2017
@theofidry fromsemver:
|
dunglas commentedFeb 1, 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.
@theofidry I don't think so. People using 2.8 LTS should not be annoyed with a deprecation in a patch version. It works well as is. This improvement is really a new feature. |
theofidry commentedFeb 1, 2017
fair enough |
sstok commentedFeb 21, 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.
|
chalasr commentedFeb 21, 2017
@sstok Using public aliases works fine on my side. The exception message make me think it's unrelated. Maybe open an issue showing the failing service definition (from |
sstok commentedFeb 21, 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.
I used
Should be
|
Uh oh!
There was an error while loading.Please reload this page.
#18040,#17783https://github.com/symfony/symfony/pull/21494/files?w=1
This PR deprecates autowiring-types and replaces them by plain aliases.
ping@dunglas@weaverryan
Eg instead of
just do: