@@ -410,21 +410,26 @@ Injecting Multiple Workflows
410
410
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
411
411
412
412
Use 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 ::
414
414
415
415
use Symfony\Component\DependencyInjection\ServiceLocator;
416
416
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
417
417
418
418
class MyClass
419
419
{
420
420
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')]
422
424
private ServiceLocator $workflows,
423
425
) {
424
426
}
425
427
426
428
public function someMethod(): void
427
429
{
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')
428
433
$workflow = $this->workflows->get('user_registration');
429
434
430
435
// ...
@@ -433,8 +438,15 @@ inject several workflows into the same class::
433
438
434
439
.. tip ::
435
440
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
+ }
438
450
439
451
.. _workflow_using-events :
440
452
0 commit comments