Skip to content

Commit 0db7228

Browse files
[DependencyInjection] Autowire arguments using the #[TaggedIterator] attribute
1 parent db74d6d commit 0db7228

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

service_container/tags.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,26 @@ application handlers::
591591
}
592592
}
593593

594+
Injecting tagged services can be also be done through autowiring thanks to the
595+
``#[TaggedIterator]`` attribute. This attribute must be directly used on the
596+
argument to autowire::
597+
598+
// src/HandlerCollection.php
599+
namespace App;
600+
601+
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
602+
603+
class HandlerCollection
604+
{
605+
public function __construct(#[TaggedIterator('app.handler')] iterable $handlers)
606+
{
607+
}
608+
}
609+
610+
.. versionadded:: 5.3
611+
612+
The ``#[TaggedIterator]`` attribute was introduced in Symfony 5.3 and requires PHP 8.
613+
594614
.. seealso::
595615

596616
See also :doc:`tagged locator services </service_container/service_subscribers_locators>`

0 commit comments

Comments
 (0)