@@ -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,54 @@ 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
+ This can be very useful when many services share some tag that cannot be
480
+ inherited from an abstract definition:
481
+
482
+ .. configuration-block ::
483
+
484
+ .. code-block :: yaml
485
+
486
+ # app/config/services.yml
487
+ services :
488
+ # ...
489
+
490
+ _instanceof :
491
+ class : AppBundle\Domain\LoaderInterface
492
+ public : true
493
+ tags : ['app.domain_loader']
494
+
495
+ .. code-block :: xml
496
+
497
+ <!-- app/config/services.xml -->
498
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
499
+ <container xmlns =" http://symfony.com/schema/dic/services"
500
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
501
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
502
+ http://symfony.com/schema/dic/services/services-1.0.xsd" >
503
+
504
+ <services >
505
+ <!-- ... -->
506
+
507
+ <instanceof id =" AppBundle\Domain\LoaderInterface" public =" true" >
508
+ <tag name =" app.domain_loader" />
509
+ </instanceof >
510
+ </services >
511
+ </container >
512
+
513
+ .. code-block :: php
514
+
515
+ // app/config/services.php
516
+ use AppBundle\Domain\LoaderInterface;
517
+
518
+ $container->registerForAutoconfiguration(LoaderInterface::class)
519
+ ->addTag('app.domain_loader');
520
+
471
521
What about Performance
472
522
----------------------
473
523
0 commit comments