@@ -410,21 +410,26 @@ Injecting Multiple Workflows
410410~~~~~~~~~~~~~~~~~~~~~~~~~~~~
411411
412412Use the :ref: `AutowireLocator <service-locator_autowire-locator >` attribute to
413- inject several workflows into the same class ::
413+ lazy-load all workflows and get the one you need ::
414414
415415 use Symfony\Component\DependencyInjection\ServiceLocator;
416416 use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
417417
418418 class MyClass
419419 {
420420 public function __construct(
421- #[AutowireLocator('blog_publishing', 'user_registration')]
421+ // 'workflow' is the service tag name and injects both workflows and state machines;
422+ // 'name' tells Symfony to index services using that tag property
423+ #[AutowireLocator('workflow', 'name')]
422424 private ServiceLocator $workflows,
423425 ) {
424426 }
425427
426428 public function someMethod(): void
427429 {
430+ // if you use the 'name' tag property to index services (see constructor above),
431+ // you can get workflows by their name; otherwise, you must use the full
432+ // service name with the 'workflow.' prefix (e.g. 'workflow.user_registration')
428433 $workflow = $this->workflows->get('user_registration');
429434
430435 // ...
@@ -433,8 +438,15 @@ inject several workflows into the same class::
433438
434439.. tip ::
435440
436- Injecting multiple workflows into your :ref: `workflow listeners <workflow_using-events >`
437- can help you simplify shared logic.
441+ You can also inject only workflows or only state machines::
442+
443+ public function __construct(
444+ #[AutowireLocator('workflow.workflow', 'name')]
445+ private ServiceLocator $workflows,
446+ #[AutowireLocator('workflow.state_machine', 'name')]
447+ private ServiceLocator $stateMachines,
448+ ) {
449+ }
438450
439451.. _workflow_using-events :
440452
0 commit comments