@@ -244,8 +244,7 @@ Defining a Service Locator
244
244
245
245
To manually define a service locator, create a new service definition and add
246
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. 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:
249
248
250
249
.. configuration-block ::
251
250
@@ -259,6 +258,9 @@ there is no id specified for the service it will inherit its external id.
259
258
-
260
259
App\FooCommand : ' @app.command_handler.foo'
261
260
App\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
+
262
264
# if you are not using the default service autoconfiguration,
263
265
# add the following tag to the service definition:
264
266
# tags: ['container.service_locator']
@@ -275,8 +277,10 @@ there is no id specified for the service it will inherit its external id.
275
277
276
278
<service id =" app.command_handler_locator" class =" Symfony\Component\DependencyInjection\ServiceLocator" >
277
279
<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" />
280
284
</argument >
281
285
<!--
282
286
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.
301
305
->setArguments([[
302
306
'App\FooCommand' => new Reference('app.command_handler.foo'),
303
307
'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
+ )))
305
311
// if you are not using the default service autoconfiguration,
306
312
// add the following tag to the service definition:
307
313
// ->addTag('container.service_locator')
@@ -314,7 +320,7 @@ there is no id specified for the service it will inherit its external id.
314
320
315
321
.. versionadded :: 4.2
316
322
317
- The ability to add services without specifying an id was introduced in
323
+ The ability to add services without specifying their id was introduced in
318
324
Symfony 4.2.
319
325
320
326
.. note ::
0 commit comments