Skip to content

[DependencyInjection] Allow injecting tagged iterator as service locator arguments #43015

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

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

IonBazan
Copy link
Contributor

@IonBazan IonBazan commented Sep 14, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR symfony/symfony-docs#15821

Not sure if this is a feature or bug fix - kindly update the description and target branch and I will backport the changes for older version if needed.
This feature allows creating a named (reusable) service locator using tagged services:

services:
    _instanceof:
        App\Command\HandlerInterface:
            tags: ['app.command_handler']
    
    app.command_handlers:
        class: Symfony\Component\DependencyInjection\ServiceLocator
        arguments: [!tagged_iterator { tag: 'app.command_handler', default_index_method: 'getCommandName' }]
            
    App\CommandBus:
        arguments: ['@app.command_handlers']
            
    App\AnotherCommandBus:
        arguments: ['@app.command_handlers']

Prior to this change, following error would be thrown:

Invalid definition for service "app.command_handlers": an array of references is expected as first argument when the "container.service_locator" tag is set.

@IonBazan IonBazan changed the title Allow injecting tagged iterator as service locator arguments [DependencyInjection] Allow injecting tagged iterator as service locator arguments Sep 14, 2021
@derrabus derrabus added this to the 5.4 milestone Sep 15, 2021
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

thanks
that's a new feature for sure
can you please have a look at the doc and submit a PR if possible?

@IonBazan
Copy link
Contributor Author

Sure, will look into that!

@nicolas-grekas
Copy link
Member

Thank you @IonBazan.

@nicolas-grekas nicolas-grekas merged commit 2018f0c into symfony:5.4 Sep 17, 2021
@IonBazan IonBazan deleted the tagged-argument-locator branch September 17, 2021 08:47
This was referenced Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants