Dependency Injection
suggest changeRemarks
Wikipedia definition of dependency injection is:
In software engineering, dependency injection is a software design pattern that implements inversion of control for resolving dependencies. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it.
John Munsch's analogy: when you go and get things out of the refrigerator for yourself, you can cause problems. You might leave the door open, you might get something Mommy or Daddy doesn't want you to have. You might even be looking for something we don't have or which has expired. What you should be doing is stating a need, "I need something to drink with lunch," and then we will make sure you have something when you sit down to eat. Collaborating classes should rely on the surrounding code to provide what they need.
Dependency injection using MEF shows one way to supply an ILogger without the consumer naming a concrete logger.