I’ve struggled with explaining Service Locator as an anti-pattern. I’ve addressed certain cons of service locator and pros of constructor injection. However, I think I overlooked a fundamental misconception that would reasonably push developers away from constructor injection: a belief that constructor injection exposes dependency chains across the system.
Scott Wlaschin posted an incredible series on dependency injection. It clarifies the different techniques and cases where each is useful. I noticed an interesting relationship between the techniques and the layers I use to categorize services.
Many have discussed the issues with the service locator anti-pattern for dependency management. However, I’ve repeatedly run into an issue that I haven’t seen discussed yet: it causes circular references.