What is Dependency Injection?

A

Anonieko

Pigsaw said...


"You don't want to hard code dependencies into your classes, because
then you can't test them without relying on the dependent classes. So
you "inject" those dependencies simply by setting them as properties -
possibly in the constructor, possibly with setter methods. And it
becomes all the easier if you have a little container which manages
how to configure those dependencies (properties) before they're
injected (set). "

Any shorter one?
 
G

Guest

Dependency injection is creating a wrapper around classes that your class
depends on.

You can than build stand-alone test cases that no longer "depend" on other
classes.
 
M

Michael Nemtsev, MVP

Hello Anonieko,

read there http://www.martinfowler.com/articles/injection.html


---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


A> Pigsaw said...
A>
A> "You don't want to hard code dependencies into your classes, because
A> then you can't test them without relying on the dependent classes. So
A> you "inject" those dependencies simply by setting them as properties
A> - possibly in the constructor, possibly with setter methods. And it
A> becomes all the easier if you have a little container which manages
A> how to configure those dependencies (properties) before they're
A> injected (set). "
A>
A> Any shorter one?
A>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top