Quicker, Easier, More Seductive: Names, Usage, and Intent

Yesterday’s post in this unexpected series on Dependency Injection vs Service Locator generated a lot of excellent and productive feedback in Twitter, on the PHP-FIG mailing list, and in the comments. In that post, I opined that there was a significant difference between how Service Locator containers and Dependency Injection containers are implemented. This came … Continue reading Quicker, Easier, More Seductive: Names, Usage, and Intent

Quicker, Easier, More Seductive: How To Tell A DI Container From A Service Locator

(In this unexpected series, we’ve been talking about the use of Service Locator versus Dependency Injection.) UPDATE: Please see the next post in this series for important corrections and updates regarding the essay below. It is easy to confuse a Dependency Injection container with a Service Locator. They are very similar to each other. The … Continue reading Quicker, Easier, More Seductive: How To Tell A DI Container From A Service Locator

Quicker, Easier, More Seductive: The Difference Between Factories, Registries, and Service Locators

In last week’s episode of this unexpected series, I said, “Go ahead and use Service Locator, but make sure each Locator contains only one type of object. This condition of restraint will keep a single locator from becoming a menace.” (I recommend “real” dependency injection containers as the preferred inversion-of-control mechanism; try the Aura.Di container.) … Continue reading Quicker, Easier, More Seductive: The Difference Between Factories, Registries, and Service Locators

Quicker, Easier, More Seductive: Restraining Your Service Locators

tl;dr: Go ahead and use Service Locator, but make sure each Locator contains only one type of object. This condition of restraint will keep a single locator from becoming a menace. Quicker, Easier, More Seductive I mentioned in passing last week, “When it comes to Inversion of Control, a Service Locator is like the Dark … Continue reading Quicker, Easier, More Seductive: Restraining Your Service Locators

ServiceLocator is like the Dark Side: Quicker, Easier, More Seductive

When it comes to Inversion of Control, a Service Locator is like the Dark Side of the Force: quicker, easier, more seductive. But it gets you into trouble later on. Go with Dependency Injection whenever you can instead. A lot of things calling themselves Dependency Injection containers are actually Service Locators. If you inject the … Continue reading ServiceLocator is like the Dark Side: Quicker, Easier, More Seductive