@@ -243,8 +243,8 @@ Defining a Service Locator
243243--------------------------
244244
245245To manually define a service locator, create a new service definition and add
246- the ``container.service_locator `` tag to it. Use its `` arguments `` option to
247- include as many services as needed in it.
246+ the ``container.service_locator `` tag to it. Use the first argument of the
247+ service definition to pass a collection of services to the service locator:
248248
249249.. configuration-block ::
250250
@@ -262,6 +262,13 @@ include as many services as needed in it.
262262 # add the following tag to the service definition:
263263 # tags: ['container.service_locator']
264264
265+ # if the element has no key, the ID of the original service is used
266+ app.another_command_handler_locator :
267+ class : Symfony\Component\DependencyInjection\ServiceLocator
268+ arguments :
269+ -
270+ - ' @app.command_handler.baz'
271+
265272 .. code-block :: xml
266273
267274 <!-- config/services.xml -->
@@ -274,8 +281,10 @@ include as many services as needed in it.
274281
275282 <service id =" app.command_handler_locator" class =" Symfony\Component\DependencyInjection\ServiceLocator" >
276283 <argument type =" collection" >
277- <argument key =" App\FooCommand" type =" service" id =" app.command_handler.foo" />
278- <argument key =" App\BarCommand" type =" service" id =" app.command_handler.bar" />
284+ <argument key =" App\FooCommand" type =" service" id =" app.command_handler.foo" />
285+ <argument key =" App\BarCommand" type =" service" id =" app.command_handler.bar" />
286+ <!-- if the element has no key, the ID of the original service is used -->
287+ <argument type =" service" id =" app.command_handler.baz" />
279288 </argument >
280289 <!--
281290 if you are not using the default service autoconfiguration,
@@ -300,12 +309,24 @@ include as many services as needed in it.
300309 ->setArguments([[
301310 'App\FooCommand' => new Reference('app.command_handler.foo'),
302311 'App\BarCommand' => new Reference('app.command_handler.bar'),
303- ]])
312+ // if the element has no key, the ID of the original service is used
313+ new Reference('app.command_handler.baz'),
314+ )))
304315 // if you are not using the default service autoconfiguration,
305316 // add the following tag to the service definition:
306317 // ->addTag('container.service_locator')
307318 ;
308319
320+ .. versionadded :: 4.1
321+ The service locator autoconfiguration was introduced in Symfony 4.1. In
322+ previous Symfony versions you always needed to add the
323+ ``container.service_locator `` tag explicitly.
324+
325+ .. versionadded :: 4.2
326+
327+ The ability to add services without specifying their id was introduced in
328+ Symfony 4.2.
329+
309330.. note ::
310331
311332 The services defined in the service locator argument must include keys,
0 commit comments