@@ -298,10 +298,10 @@ This is done by having ``getSubscribedServices()`` return an array of
298
298
The above example requires using ``3.2 `` version or newer of ``symfony/service-contracts ``.
299
299
300
300
.. _service-locator_autowire-locator :
301
- .. _ service-locator_autowire-iterator :
301
+ .. _ the-autowirelocator-and-autowireiterator-attributes :
302
302
303
- The AutowireLocator and AutowireIterator Attributes
304
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
303
+ The AutowireLocator Attribute
304
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
305
305
306
306
Another way to define a service locator is to use the
307
307
:class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireLocator `
@@ -381,16 +381,17 @@ attribute::
381
381
:class: `Symfony\\ Component\\ DependencyInjection\\ Attribute\\ AutowireLocator `
382
382
attribute was introduced in Symfony 6.4.
383
383
384
+ .. _service-locator_autowire-iterator :
385
+
384
386
The AutowireIterator Attribute
385
387
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386
- Variant of the ``AutowireLocator `` that specifically provides an iterable of services
387
- based on a tag. This allows you to collect all services with a particular tag into
388
- an iterable, which can be useful when you need to iterate over a set of services
389
- rather than retrieving them individually.
390
388
391
- For example, if you want to collect all the handlers for different command types,
392
- you can use the ``AutowireIterator `` attribute to automatically inject all services
393
- tagged with a specific tag::
389
+ A variant of ``AutowireLocator `` that injects an iterable of services tagged
390
+ with a specific :doc: `tag </service_container/tags >`. This is useful to loop
391
+ over a set of tagged services instead of retrieving them individually.
392
+
393
+ For example, to collect all handlers for different command types, use the
394
+ ``AutowireIterator `` attribute and pass the tag used by those services::
394
395
395
396
// src/CommandBus.php
396
397
namespace App;
@@ -404,7 +405,7 @@ tagged with a specific tag::
404
405
{
405
406
public function __construct(
406
407
#[AutowireIterator('command_handler')]
407
- private iterable $handlers, // Collects all services tagged with 'command_handler'
408
+ private iterable $handlers, // collects all services tagged with 'command_handler'
408
409
) {
409
410
}
410
411
0 commit comments