You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #43015 [DependencyInjection] Allow injecting tagged iterator as service locator arguments (IonBazan)
This PR was merged into the 5.4 branch.
Discussion
----------
[DependencyInjection] Allow injecting tagged iterator as service locator arguments
| 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 tagg
10000
ed services:
```yml
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.
```
Commits
-------
7c86ac8 Allow injecting tagged iterator as service locator arguments
thrownewInvalidArgumentException(sprintf('Invalid definition for service "%s": an array of references is expected as first argument when the "container.service_locator" tag is set.', $this->currentId));
0 commit comments