Saturday, November 7, 2009

What is Inversion of control and Dependency injection

recently we started to use Unity for projects. Unity is a way to facilitate dependency injection into you code.

And we where using some of the terms often related to this topic and it was confusing me. I decided to get my facts straight.

Inversion Of Control
Inversion of control article that i have found usefull
This article states that inversion of control is a priciple.
a short statement that signifies the base principle:
"Don't call us, we will call you"

the principle comes down to the following:
A Control gets all his data and events from the outside and itself does not know anything about the context it is being used in. This results in lousely coupled Code/controls which in turn should make them more reusable.
Dependency Injection
Dependency injection is a way to achieve Inversion of control

http://www.codeproject.com/KB/aspnet/IOCDI.aspx

Conlusion

Inversion of control is a principle with the goal to help you create better, more reusable code

Dependency injection is a specific method of achieving inversion of control.(Unity is a method for dependency injection)

No comments:

Post a Comment