Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] Tag subscribers for collecting tagged services? #22649

Closed
@chalasr

Description

@chalasr
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes
Symfony version 3.4

Service subscribers can be used by services knowing exactly what services they need (requires a static list of identifiers), creating service locators from a compiler pass remain the only way to collect and map services corresponding to a given tag, injecting the locator by hand into the requesting service.

Would it be interesting to give the ability to service subscribers to request all registered services for a tag (tagged services subscribers)? This could be done by introducing a variant of ServiceSubscriberInterface like:

interface TagSubscriberInterface
{
    public function getSubscribedTag()
    {
        return [
            'console.command', // request access to services tagged "console.command"
            'console.command' => Command::class // skips non Command subclasses
        ];
    }
}

It would remove the need for creating compiler passes that are dedicated to collect services without performing any special treatment on those.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions