diff --git a/service_container/service_subscribers_locators.rst b/service_container/service_subscribers_locators.rst index 2c057067927..04430276595 100644 --- a/service_container/service_subscribers_locators.rst +++ b/service_container/service_subscribers_locators.rst @@ -140,6 +140,18 @@ count and iterate over the services of the locator:: The :class:`Symfony\\Contracts\\Service\\ServiceCollectionInterface` was introduced in Symfony 7.1. +Without autowire +~~~~~~~~~~~~~~~~ + +If you are not using autowire you need to require either ``Psr\Container\ContainerInterface`` or ``Symfony\Contracts\Service\ServiceProviderInterface`` as a ``__construct`` argument or as a method call like ``setContainer(Psr\Container\ContainerInterface $container)``. + +.. code-block:: diff + + $services->set('my_service', SomeClass::class) + + ->call('setContainer', [service(ContainerInterface::class)]) + + ->tag('container.service_subscriber') + ; + Including Services ------------------