Maxim Mironjuk
-
February 25, 2026
Autowiring resolves most dependencies in Symfony automatically based on type, and it is rightfully the default approach for constructor injection. But as soon as several services implement the same interface, for example multiple payment gateways or multiple export formats, the container can no longer decide unambiguously which concrete implementation is meant, and it fails at compile time. This article shows how ServiceLocator and the AutowireLocator attribute provide a deliberate, explicit, and still testable way out for exactly this case, and why that is fundamentally different from the classic injected service container, which is rightly considered an anti-pattern.