Technical Mid Level

How do tagged services work in Symfony? Explain how you define, collect, and use tagged services with a practical example.

Quick Tip

Show the pattern: I tag services with AutoconfigureTag and inject them with TaggedIterator. For example, I tag all report generators and inject the collection into a ReportManager that iterates and delegates. Autoconfigure handles built-in tags like event subscribers automatically.

What good answers include

Tagged services let you group related services under a label and inject them as a collection. You tag services in services.yaml or via #[AutoconfigureTag] and #[TaggedIterator] attributes. The container collects all services with a given tag and injects them — typically into a service that iterates over them. Classic examples: Twig extensions (twig.extension), event subscribers (kernel.event_subscriber), and custom plugin systems. Compiler passes can also process tags for advanced scenarios. Strong candidates explain: that autoconfigure handles common tags automatically, how to define priority on tags, and when you would use a tagged locator (lazy loading) versus a tagged iterator (eager loading).

What interviewers are looking for

Tests understanding of the DI container beyond basic autowiring. Candidates who manually wire every dependency instead of using tags are creating rigid, hard-to-extend code. Those who understand tagged iterators and locators can build plugin-style architectures.

← All Symfony questions