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

[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

Merged

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedFeb 1, 2017
edited by weaverryan
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?yes
Tests pass?yes
Fixed tickets#21351,#19970,#18040,#17783
LicenseMIT
Doc PRsymfony/symfony-docs#7445

https://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

<serviceid="annotations.reader"class="Doctrine\Common\Annotations\AnnotationReader"public="false">    <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type></service>

just do:

<serviceid="annotations.reader"class="Doctrine\Common\Annotations\AnnotationReader"public="false" /><serviceid="Doctrine\Common\Annotations\Reader"alias="annotations.reader"public="false" />

chalasr, ogizanagi, mnapoli, theofidry, and TomasVotruba reacted with thumbs up emojimnapoli, theofidry, and Koc reacted with heart emoji
@weaverryan
Copy link
Member

@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 ;)

vria reacted with thumbs up emoji

@nicolas-grekas
Copy link
MemberAuthor

nicolas-grekas commentedFeb 1, 2017
edited
Loading

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.

ogizanagi, stof, and chalasr reacted with heart emoji

DependencyInjection
-------------------

* Autoriwing-types have been deprecated, use aliases instead.
Copy link
Contributor

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?

Copy link
Member

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

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

example added

@stof
Copy link
Member

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.

@chalasr
Copy link
Member

Far simpler 👍

@dunglas
Copy link
Member

Great! 👍

@weaverryan
Copy link
Member

Ha, I missed the change toAutowirePass. Of course, it makes sense! We'll need a docs issue so we can update things.

👍

$definition =$container->findDefinition('templating');
$definition->setAutowiringTypes(array(ComponentEngineInterface::class,FrameworkBundleEngineInterface::class));
$container->setAlias(ComponentEngineInterface::class,'templating');
$container->setAlias(FrameworkBundleEngineInterface::class,'templating');
Copy link
Member

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

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

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

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

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)

DependencyInjection
-------------------

* Autoriwing-types have been deprecated, use aliases instead.
Copy link
Member

Choose a reason for hiding this comment

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

typo here

DependencyInjection
-------------------

* Autoriwing-types have been removed, use aliases instead.
Copy link
Member

Choose a reason for hiding this comment

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

typo here

@nicolas-grekas
Copy link
MemberAuthor

@stof comments addressed, thanks

@stof
Copy link
Member

stof commentedFeb 1, 2017

btw, my comment about using private aliases for this is also true for the documentation when writing it

chalasr reacted with thumbs up emoji

@weaverryan
Copy link
Member

Docs issue created - I added a note on there about your (Stof) "private aliases" comment.

@fabpot
Copy link
Member

Thank you@nicolas-grekas.

mnapoli and sstok reacted with hooray emoji

@fabpotfabpot merged commitb11d391 intosymfony:masterFeb 1, 2017
fabpot added a commit that referenced this pull requestFeb 1, 2017
…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
Copy link
Contributor

@nicolas-grekas shouldn't this be back-ported to 2.8? Autowiring has been introduced there and IIRC there isautowiring-types there as well. It would allow people to never useautowiring-types in the first place and it could be considered as a bug rather than a feature.

robfrawley reacted with thumbs down emojichalasr reacted with confused emoji

@chalasr
Copy link
Member

@theofidry fromsemver:

  • Minor version Y (x.Y.z | x > 0)
    It MUST be incremented if any public API functionality is marked as deprecated

@dunglas
Copy link
Member

dunglas commentedFeb 1, 2017
edited
Loading

@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
Copy link
Contributor

fair enough

@sstok
Copy link
Contributor

sstok commentedFeb 21, 2017
edited
Loading

```Using the attribute "class" is deprecated for the service "2_d44d409a6f8ec9217d33bfd752130a5a50dfdd4314933b690caf9278e3ece37c" which is defined as an alias in "/[..]/rollerworks/search-bundle/src/DependencyInjection/../Resources/config/search_processor.xml". Allowed attributes for service aliases are "alias", "id" and "public". The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported attributes: 1x    1x in SearchProcessorTest::testEmptySearchCodeIsValid from Rollerworks\Bundle\SearchBundle\Tests\Functional```Never mind 🙈 class !== id 😅

@chalasr
Copy link
Member

@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 (fromsearch_processor.xml)?

@sstok
Copy link
Contributor

sstok commentedFeb 21, 2017
edited
Loading

I usedclass instead ofid for the class 🙂

<service alias="rollerworks_search.http_foundation_search_processor" public="false" />

Should be

<service alias="rollerworks_search.http_foundation_search_processor" public="false" />

chalasr reacted with laugh emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@stofstofstof approved these changes

+1 more reviewer

@ogizanagiogizanagiogizanagi left review comments

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.

10 participants

@nicolas-grekas@weaverryan@stof@chalasr@dunglas@fabpot@theofidry@sstok@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp