Skip to content

[DI] Inject all services with a specific tag #23916

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
iluuu1994 opened this issue Aug 17, 2017 · 3 comments
Closed

[DI] Inject all services with a specific tag #23916

iluuu1994 opened this issue Aug 17, 2017 · 3 comments

Comments

@iluuu1994
Copy link
Contributor

iluuu1994 commented Aug 17, 2017

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.3.x

Currently, when you want to inject all services with a specific tag you have to write your own compiler pass as described here. Additionally, one has to use method calls instead of injecting the services into the constructor because obviously the parameter cannot be inferred.

It would be handy if there was a way to inject all services that are tagged with a specific tag, optimally indexed by their id:

Foo\Bar:
    arguments:
        - '@doctrine.orm.entity_manager'
        - '@=taggedServices("my_tag")'

Resulting in:

[
    "Foo\Service1" => Foo\Service1 {...},
    "Foo\Service2" => Foo\Service2 {...},
]

This is probably not an everyday use-case but maybe other people would be interested in this.

@iluuu1994
Copy link
Contributor Author

The @= will not work because the DI component needs to know the dependencies beforehand to do topological sorting. I wouldn't know what other syntax to use though.

@chalasr
Copy link
Member

chalasr commented Aug 17, 2017

Closing as duplicate of #12269, seems like you're not alone :)
Please consider looking at it and the relevant PR #22200 to discuss implementation details.

@chalasr chalasr closed this as completed Aug 17, 2017
@iluuu1994
Copy link
Contributor Author

@chalasr Fantastic 😄 Sorry, I was looking though the issues and couldn't find anything. Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants