@@ -22,6 +22,8 @@ which means it's always safe to upgrade across minor versions.
22
22
All of the new features are **optional **: they are not enabled by default, so you
23
23
need to actually change your configuration files to use them.
24
24
25
+ .. _`service-33-default_definition` :
26
+
25
27
The new Default services.yml File
26
28
---------------------------------
27
29
@@ -411,7 +413,7 @@ In general, the new best practice is to use normal constructor dependency inject
411
413
4) Auto-tagging with autoconfigure
412
414
----------------------------------
413
415
414
- The last big change is the ``autoconfigure `` key, which is set to ``true `` under
416
+ The fourth big change is the ``autoconfigure `` key, which is set to ``true `` under
415
417
``_defaults ``. Thanks to this, the container will auto-tag services registered in
416
418
this file. For example, suppose you want to create an event subscriber. First, you
417
419
create the class::
@@ -468,6 +470,59 @@ Many autoconfigured tags have an optional priority. If you need to specify a pri
468
470
(or any other optional tag attribute), no problem! Just :ref: `manually configure your service <services-manually-wire-args >`
469
471
and add the tag. Your tag will take precedence over the one added by auto-configuration.
470
472
473
+ 5) Auto-configure with _instanceof
474
+ ----------------------------------
475
+
476
+ And the final big change is ``_instanceof ``. It acts as a default definition
477
+ template (see `service-33-default_definition `_), but only for services whose
478
+ class matches a defined one.
479
+
480
+ This can be very useful when many services share some tag that cannot be
481
+ inherited from an abstract definition:
482
+
483
+ .. configuration-block ::
484
+
485
+ .. code-block :: yaml
486
+
487
+ # app/config/services.yml
488
+ services :
489
+ # ...
490
+
491
+ _instanceof :
492
+ class : AppBundle\Domain\LoaderInterface
493
+ public : true
494
+ tags : ['app.domain_loader']
495
+
496
+ .. code-block :: xml
497
+
498
+ <!-- app/config/services.xml -->
499
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
500
+ <container xmlns =" http://symfony.com/schema/dic/services"
501
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
502
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
503
+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
504
+
505
+ <services >
506
+ <!-- ... -->
507
+
508
+ <instanceof id =" AppBundle\Domain\LoaderInterface" public =" true" >
509
+ <tag name =" app.domain_loader" />
510
+ </instanceof >
511
+ </services >
512
+ </container >
513
+
514
+ .. code-block :: php
515
+
516
+ // app/config/services.php
517
+ use AppBundle\Domain\LoaderInterface;
518
+
519
+ // ...
520
+
521
+ /* This method returns a child definition to define the default
522
+ configuration of the given class or interface */
523
+ $container->registerForAutoconfiguration(LoaderInterface::class)
524
+ ->addTag('app.domain_loader');
525
+
471
526
What about Performance
472
527
----------------------
473
528
0 commit comments