Skip to content

Commit cb545ff

Browse files
authored
[DI] Automatically applying a tag to all services implementing an interface
1 parent f89e2d0 commit cb545ff

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

service_container/tags.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ then some tags are automatically applied for you. That's true for the ``twig.ext
7070
tag: the container sees that your class extends ``Twig_Extension`` (or more accurately,
7171
that it implements ``Twig_ExtensionInterface``) and adds the tag for you.
7272

73+
In order to have a tag automatically applied to all your services that implement an interface,
74+
you should create an extension following the steps described in :doc:`/bundles/extension`,
75+
then in the ``load()`` method call ``registerForAutoconfiguration()`` and apply your tag::
76+
77+
// src/AppBundle/DependencyInjection/AppExtension.php
78+
79+
// ...
80+
public function load(array $configs, ContainerBuilder $container)
81+
{
82+
$container->registerForAutoconfiguration(CustomInterface::class)
83+
->addTag('app.custom_tag')
84+
;
85+
}
86+
7387
Creating custom Tags
7488
--------------------
7589

0 commit comments

Comments
 (0)