Skip to content

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

Closed
@iluuu1994

Description

@iluuu1994
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions