IoC Container Vs. Service Locator

This post has migrated to https://beginningprogrammer.com/programming/ioc-container-vs-service-locator/

Comments

Derick Bailey said…
great post, Fernando! I had IoC vs ServiceLocator confused for the last 3 years, honestly. I had to go back and re-read that Fowler article a few times in the last week before it really sunk in.

Be careful about saying "coding against abstractions. In C# we use interfaces" - abstraction does not imply interface, even in C#.

http://www.lostechies.com/blogs/derickbailey/archive/2008/10/20/dependency-inversion-abstraction-does-not-mean-interface.aspx
Fernando Zamora said…
Derick, you are absolutely right. I didn't give it think it trough when I wrote that line. Abstractions appear in every language in many different forms. Anything that hides the implementation details for that matter is a form of abstraction. Abstraction is the "what" hiding the "how".
A service locator may as well inject dependencies (using itself to construct them). There is no difference between Service Locator and IoC container if you take them in isolation.

The only difference is how you use them in your application.

Popular posts from this blog

Why I Hate Regular Expressions

Simple Example of Using Pipes with C#

Why a Programmer Must Have Sales Skills