While writing my article on DI on mORMot, Stefan Glienke correctly commented on a first draft that I was confusing the Dependency Injection and the Service Locator patterns. This led me to do some investigation, and to be honest, I have more questions now.

While writing my article on DI on mORMot, Stefan Glienke correctly commented on a first draft that I was confusing the Dependency Injection and the Service Locator patterns. This led me to do some investigation, and to be honest, I have more questions now.

I now understand the difference between the two patterns, but, I've found that some people feel that Service Locator is an anti-pattern, (which is a pity as I was quite fond of it) as it hides your dependencies, and that is why constructor based dependency injection is preferred - the compiler can assist with detecting breaking changes, and CodeInsight provides valuable information to the developer. (I should add "when creating a new system", because retro fitting DI will be a nightmare)

Am I right, that on a very basic level, DI simply states - provide your dependencies as parameters, rather than fetching them? If that case the pattern will even work for good old procedural programming.
https://tamingthemormot.wordpress.com/2015/07/20/dependency-injection-the-mormot-way/

Comments