Possible Duplicate:
Help with Dependency Injection in .NET
Hi friends,
It is a couple of days that I’ve been seeing Dependency Injection in some websites !
Would you please say :
What is it ?
What’s the benefits of using it ?
Thanks a lot.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dependency Injection is a very simple concept (the implementation, on the other hand, can be quite complex).
Dependency Injection is simply allowing the caller of a method to inject dependent objects into the method when it is called. For example if you wanted to allow the following piece of code to swap SQL providers without recompiling the method:
You could ‘Inject’ the SQL Provider:
There’s also Constructor Injection where you inject the dependency of an object during instanciation.
The whole point of Dependency Injection is to reduce coupling between the pieces of your application. The caller can substitute whatever it needs to get the job done without modifying the method it’s calling (or the object it’s creating).