Service Locator vs Dependency Injection
While I've been exclusively using DI since I wrote articles like this one or this one (and several others on the subject of Service Locators), I think I finally figured out how to explain why DI is better: it's because it forces a design change in classes. Start with the normal mess, where your method directly initializes a concrete class, let's say in the constructor: public class DoesSomethingThatRequiresLogging { public DoesSomethingThatRequiresLogging() { logger = new FileLogger(@"c:\temp\log.txt"); } // private FileLogger logger; } Your methods happily call logger.Log(...) and all is good with the world. However, at some point you have to test this, or reuse it, or change it to log to a database table instead of a file. Ouch. The first solution is the use of a service locator. Create the logger outside of the constructor and use it as required: // in Main ServiceLocator.Register(new FileLogger(@"c:\temp\lo...