<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>yes</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.3.x</td>
</tr>
</tbody>
</table>
<p dir="auto">Currently, when you want to inject all services with a specific tag you have to write your own compiler pass <a href="https://symfony.com/doc/current/service_container/tags.html" rel="nofollow">as described here</a>. Additionally,  one has to use method calls instead of injecting the services into the constructor because obviously the parameter cannot be inferred.</p>
<p dir="auto">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:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Foo\Bar:
    arguments:
        - '@doctrine.orm.entity_manager'
        - '@=taggedServices(&quot;my_tag&quot;)'"><pre class="notranslate"><span class="pl-ent">Foo\Bar</span>:
    <span class="pl-ent">arguments</span>:
        - <span class="pl-s"><span class="pl-pds">'</span>@doctrine.orm.entity_manager<span class="pl-pds">'</span></span>
        - <span class="pl-s"><span class="pl-pds">'</span>@=taggedServices("my_tag")<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">Resulting in:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[
    &quot;Foo\Service1&quot; =&gt; Foo\Service1 {...},
    &quot;Foo\Service2&quot; =&gt; Foo\Service2 {...},
]"><pre class="notranslate">[
    "<span class="pl-s">Foo\Service1</span>" =&gt; <span class="pl-v">Foo</span>\<span class="pl-v">Service1</span> {<span class="pl-c1">.</span>.<span class="pl-c1">.</span>},
    "<span class="pl-s">Foo\Service2</span>" =&gt; <span class="pl-v">Foo</span>\<span class="pl-v">Service2</span> {<span class="pl-c1">.</span>.<span class="pl-c1">.</span>},
]</pre></div>
<p dir="auto">This is probably not an everyday use-case but maybe other people would be interested in this.</p>
<p dir="auto">Similar issue to (in the sense of having a similar context) than <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="38601842" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/11460" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/11460/hovercard" href="https://github.com/symfony/symfony/issues/11460">#11460</a></p>
<p dir="auto">In Drupal we have a lot of tagged services which are injected into a single one. When we started most of them had custom Compiler Passed, but than we realized that we can easily extract that into a common service:</p>
<p dir="auto">This would be the "collector" service:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  breadcrumb:
    class: Drupal\Core\Breadcrumb\BreadcrumbManager
    arguments: ['@module_handler']
    tags:
      - { name: service_collector, tag: breadcrumb_builder, call: addBuilder }"><pre class="notranslate"><code class="notranslate">  breadcrumb:
    class: Drupal\Core\Breadcrumb\BreadcrumbManager
    arguments: ['@module_handler']
    tags:
      - { name: service_collector, tag: breadcrumb_builder, call: addBuilder }
</code></pre></div>
<p dir="auto">and then you do something like that in the client service:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  forum.breadcrumb.listing:
    class: Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
    arguments: ['@entity.manager', '@config.factory', '@forum_manager']
    tags:
      - { name: breadcrumb_builder, priority: 314 }"><pre class="notranslate"><code class="notranslate">  forum.breadcrumb.listing:
    class: Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
    arguments: ['@entity.manager', '@config.factory', '@forum_manager']
    tags:
      - { name: breadcrumb_builder, priority: 314 }
</code></pre></div>
<p dir="auto">Any oppinions?</p>