The Service Container
A compiled DI container that resolves dependencies at build time and generates raw PHP, so production has zero runtime resolution cost.
- Built once during cache warmup, dumped as plain PHP, and just executed on each request.
- In dev it rebuilds when config or files change; in prod you warm the cache during deploy.
- Configured via `services.yaml`, attributes (`#[AsService]`, `#[AutowireService]`), or compiler passes.
- Tags group services for collection injection (e.g. all event subscribers, all form types).
- `bin/console debug:container` lists every service and what implements an interface.
- `bin/console debug:autowiring` shows what types are autowire-able in your project.
Common gotchas
- Clearing the cache in production must happen before traffic hits the new code, otherwise you serve a stale container.
- Anything pulled from `ContainerInterface::get()` at runtime is slow and hides dependencies — only do it in factories.