interfaces-and-autowiring

Installation
SKILL.md

Interfaces And Autowiring (Symfony)

Use when

  • A service depends on a concrete class and must be swappable or replaced in tests.
  • Several implementations of one interface exist and the right one must be injected.
  • Adding cross-cutting behavior (logging, caching, retries) around an existing service.
  • Injecting scalars, parameters, env vars, or every service carrying a tag.
  • Autowiring fails with "cannot autowire" or an ambiguous type.

Default workflow

  1. Extract a focused interface for what the consumer actually needs.
  2. Let autowiring bind it when there is a single implementation.
  3. With several implementations, pick one per consumer through a named alias and #[Target].
  4. Add behavior around a service with #[AsDecorator] instead of editing or extending it.
  5. Inject scalars with #[Autowire] and tagged collections with #[AutowireIterator].
  6. Confirm the result with debug:autowiring for each type involved.
Installs
80
GitHub Stars
224
First Seen
Sep 18, 2026