Stats

118 Contributors: 4
2017-07-25
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook

Dependency Injection

Download c# eBook

Remarks

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.

**This site features an answer to the question How to explain Dependency Injection to a 5-year old. The most highly rated answer, provided by John Munsch provides a surprisingly accurate analogy targeted at the (imaginary) five-year-old inquisitor: 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 even 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. What this means in terms of object-oriented software development is this: collaborating classes (the five-year-olds) should rely on the infrastructure (the parents) to provide

** This code uses MEF to dynamically load the dll and resolve the dependencies. ILogger dependency is resolved by MEF and injectd into the user class. User class never receives Concrete implementation of ILogger and it has no idea of what or which type of logger its using.**

Related Examples