Sunday, August 10, 2014

Service locator is not an anti pattern. | jgauffin's coding den

Service locator is not an anti pattern. | jgauffin's coding den:



Summary

My point is that you can abuse any pattern, but that doesn’t make it an anti pattern. The reason to why Singleton and Service Locator got such a bad reputation is that they are easy to understand, implement and use. The problem is that the implementors/users haven’t fully understood the problem that the patterns are trying to solve.
Here is a challenge for all of you that claims that it’s an anti pattern:
Pretend that you are developer at Microsoft working with ASP.NET MVC. You want to let your framework users inject dependencies into the Controllers. But since you’ve read that service location is an anti pattern you’ll want to replace it with something else (which supports scoping).
Anyone of you that can present a solution which is cleaner than my defined interfaces above will get my eternal respect.

No comments: