What’s the difference between the Dependency Injection and Service Locator patterns?

Both patterns seem like an implementation of the principle of inversion of control. That is, that an object should not know how to construct its dependencies. Dependency Injection (DI) seems to use a constructor or setter to “inject” it’s dependencies. Example of using Constructor Injection: //Foo Needs an IBar public class Foo { private IBar … Read more