views:

211

answers:

6

Possible Duplicate:
What is dependency injection?

Spring is the framework from where the concept Dependency Injection came to picture.

What is purpose of DI ? How does it benefit ? How is it implemented ?

+5  A: 

Start here.

Also see A-beginners-guide-to-Dependency-Injection.

Elsewhere on SO:

Zaki
+1 for clean, informative answer without having to re-write what was already written
Justian Meyer
+1  A: 

Try taking a look at: http://martinfowler.com/articles/injection.html

pdbartlett
+4  A: 

What is the purpose of DI?

The purpose of Dependency Injection is to reduce coupling in your application to make it more flexible and easier to test.

How does it benefit?

Objects don't have hard coded dependencies. If you need to change the implementation of a dependency, all you have to do is Inject a different type of Object.

How does it implemented?

There are various methods of Dependency Injection. Check out the Wikipedia article to see examples of each. Once you understand those, you can start investigating the various Dependency Injection frameworks.

Justin Niessner
A: 

DI allows us to swap out components, improve testability and ensure that components are loosely coupled. DI allows to resolve dependencies at run time using DI containers such as Windsor Castle, Unity, Spring.net, MEF which allows applications to be extensible.

nitroxn
A: 

Very short,

What is the purpose of DI? With dependency injection, objects don't define their dependencies themselves, the dependencies are injected to them as needed.

How does it benefit ? The objects don't kneed to know where and how to get their dependencies, which results in loose coupling between objects, which makes them a lot easier to test.

How does it implemented ? Usually a container manages the lifecycle of objects and their dependencies based on a configuration file or annotations.

nkr1pt