Skip to content

Commit 7c1a4b4

Browse files
committed
Add attribute configuration block for reusable locator
1 parent 738c893 commit 7c1a4b4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

service_container/service_subscribers_locators.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,23 @@ Now you can inject the service locator in any other services:
570570

571571
.. configuration-block::
572572

573+
.. code-block:: php-attributes
574+
575+
// src/CommandBus.php
576+
namespace App;
577+
578+
use Psr\Container\ContainerInterface;
579+
use Symfony\Component\DependencyInjection\Attribute\Autowire;
580+
581+
class CommandBus
582+
{
583+
public function __construct(
584+
#[Autowire(service: 'app.command_handler_locator')]
585+
private ContainerInterface $locator,
586+
) {
587+
}
588+
}
589+
573590
.. code-block:: yaml
574591
575592
# config/services.yaml

0 commit comments

Comments
 (0)