Skip to content

[DI] Use variadics for autowiring tagged services #23608

@zmitic

Description

@zmitic
Q A
Bug report? no
Feature request? yes
BC Break report? not sure
RFC? yes
Symfony version 3.3.5

Although a documentation doesn't describe it, tagged services can be injected via

$definition->replaceArgument(1, $arrayOfTransportDefinitions);

In all of cases I worked, a service would ever accept only one type of tagged services. Can this be used to have services autowired like this:

class TransportChain
{
    public function __construct(LoggerInterface $logger, TransportInterface ...$transports)
    {
        // ....
    }

This way user would not have to write compiler pass, giving better experience. The con is lack of injecting multiple tagged services but I don't think users do it anyway.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DependencyInjectionFeatureRFCRFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions