@@ -247,8 +247,7 @@ Defining a Service Locator
247
247
248
248
To manually define a service locator, create a new service definition and add
249
249
the ``container.service_locator `` tag to it. Use the first argument of the
250
- service definition to pass a collection of services to the service locator. If
251
- there is no id specified for the service it will inherit its external id.
250
+ service definition to pass a collection of services to the service locator:
252
251
253
252
.. configuration-block ::
254
253
@@ -262,6 +261,9 @@ there is no id specified for the service it will inherit its external id.
262
261
-
263
262
App\FooCommand : ' @app.command_handler.foo'
264
263
App\BarCommand : ' @app.command_handler.bar'
264
+ # if the element has no key, the ID of the original service is used
265
+ ' @app.command_handler.baz'
266
+
265
267
# if you are not using the default service autoconfiguration,
266
268
# add the following tag to the service definition:
267
269
# tags: ['container.service_locator']
@@ -280,6 +282,8 @@ there is no id specified for the service it will inherit its external id.
280
282
<argument type =" collection" >
281
283
<argument key =" App\FooCommand" type =" service" id =" app.command_handler.foo" />
282
284
<argument key =" App\BarCommand" type =" service" id =" app.command_handler.bar" />
285
+ <!-- if the element has no key, the ID of the original service is used -->
286
+ <argument type =" service" id =" app.command_handler.baz" />
283
287
</argument >
284
288
<!--
285
289
if you are not using the default service autoconfiguration,
@@ -304,6 +308,8 @@ there is no id specified for the service it will inherit its external id.
304
308
->setArguments(array(array(
305
309
'App\FooCommand' => new Reference('app.command_handler.foo'),
306
310
'App\BarCommand' => new Reference('app.command_handler.bar'),
311
+ // if the element has no key, the ID of the original service is used
312
+ new Reference('app.command_handler.baz'),
307
313
)))
308
314
// if you are not using the default service autoconfiguration,
309
315
// add the following tag to the service definition:
@@ -316,7 +322,7 @@ there is no id specified for the service it will inherit its external id.
316
322
``container.service_locator `` tag explicitly.
317
323
318
324
.. versionadded :: 4.2
319
- The ability to add services without specifying an id was introduced in
325
+ The ability to add services without specifying their id was introduced in
320
326
Symfony 4.2.
321
327
322
328
.. note ::
0 commit comments