Technical Mid Level

Explain how the Symfony service container works. What is the difference between autowiring and explicit service definitions, and when would you use each?

Quick Tip

Show the performance advantage: "Symfony compiles the container to raw PHP at warmup. In production, every service resolution is a direct method call with no reflection or runtime resolution — that is why it is fast."

What good answers include

The Symfony service container is a compiled dependency injection container. At build time, it resolves all dependencies, generates optimised PHP code, and caches it. Autowiring resolves dependencies by type-hint — if only one service implements an interface, Symfony injects it automatically. Explicit definitions are needed when multiple implementations exist for the same interface, when you need tagged services, or when constructor arguments are scalar values. Strong candidates mention the compiler pass system, auto-configuration via attributes, and that the compiled container has zero runtime resolution cost.

What interviewers are looking for

Core Symfony knowledge. Candidates who cannot explain the compiled container do not understand why Symfony behaves differently in dev versus prod. Those who manually wire everything when autowiring would suffice are creating unnecessary work.

← All Symfony questions