G
G
grabbee2021-11-29 12:31:34
symfony
grabbee, 2021-11-29 12:31:34

Where in the doc is the service tagging behavior described?

It doesn't work in my bundle.

# config/services.yaml
services:
    # this config only applies to the services created by this file
    _instanceof:
        # services whose classes are instances of CustomInterface will be tagged automatically
        App\Security\CustomInterface:
            tags: ['app.custom_tag']


New from 5.3 doesn't work either
#[Autoconfigure(tags: ['app.some_tag'])]
interface SomeInterface
{
    // ...
}


Found only in an answer on SO

Therefor if the service you are attempting to tag with _instanceof is not declared in the same services.yml file the tag will not be added. To tag services that implements an Interface in the entire application ...


And in my case, only registerForAutoconfiguration in the bundle extension works. Why so, and where it is described in the dock, I could not find.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2021-11-29
@grabbee

https://symfony.com/doc/current/bundles/best_pract...

Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly.

The reason is that bundles shouldn't rely on features such as service autowiring or autoconfiguration to not impose an overhead when compiling application services.

What you described is just autoconfiguration

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question