@@ -244,8 +244,7 @@ Defining a Service Locator
244244
245245To manually define a service locator, create a new service definition and add
246246the ``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. If
248- there is no id specified for the service it will inherit its external id.
247+ service definition to pass a collection of services to the service locator:
249248
250249..configuration-block ::
251250
@@ -259,6 +258,9 @@ there is no id specified for the service it will inherit its external id.
259258 -
260259App\FooCommand :' @app.command_handler.foo'
261260App\BarCommand :' @app.command_handler.bar'
261+ # if the element has no key, the ID of the original service is used
262+ ' @app.command_handler.baz'
263+
262264# if you are not using the default service autoconfiguration,
263265# add the following tag to the service definition:
264266# tags: ['container.service_locator']
@@ -275,8 +277,10 @@ there is no id specified for the service it will inherit its external id.
275277
276278 <service id =" app.command_handler_locator" class =" Symfony\Component\DependencyInjection\ServiceLocator" >
277279 <argument type =" collection" >
278- <argument key =" App\FooCommand" type =" service" id =" app.command_handler.foo" />
279- <argument key =" App\BarCommand" type =" service" id =" app.command_handler.bar" />
280+ <argument key =" App\FooCommand" type =" service" id =" app.command_handler.foo" />
281+ <argument key =" App\BarCommand" type =" service" id =" app.command_handler.bar" />
282+ <!-- if the element has no key, the ID of the original service is used-->
283+ <argument type =" service" id =" app.command_handler.baz" />
280284 </argument >
281285<!--
282286 if you are not using the default service autoconfiguration,
@@ -301,7 +305,9 @@ there is no id specified for the service it will inherit its external id.
301305 ->setArguments([[
302306 'App\FooCommand' => new Reference('app.command_handler.foo'),
303307 'App\BarCommand' => new Reference('app.command_handler.bar'),
304- ]])
308+ // if the element has no key, the ID of the original service is used
309+ new Reference('app.command_handler.baz'),
310+ )))
305311 // if you are not using the default service autoconfiguration,
306312 // add the following tag to the service definition:
307313 // ->addTag('container.service_locator')
@@ -314,7 +320,7 @@ there is no id specified for the service it will inherit its external id.
314320
315321..versionadded ::4.2
316322
317- The ability to add services without specifyingan id was introduced in
323+ The ability to add services without specifyingtheir id was introduced in
318324 Symfony 4.2.
319325
320326..note ::