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

Skip to content

Commit 375c481

Browse files
committed
minor #17652 [DependencyInjection] Autowire arguments using the #[TaggedIterator] attribute (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [DependencyInjection] Autowire arguments using the #[TaggedIterator] attribute Partially solves #15238. As tagged locator are not mentioned here, I guess it should be done somewhere else. Commits ------- 0db7228 [DependencyInjection] Autowire arguments using the #[TaggedIterator] attribute
2 parents db74d6d + 0db7228 commit 375c481

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)