Hot Proton


Leave a comment

Dependency Injection in .NET

Dependency Injection
Definition
It is a software design pattern that implements inversion of control for software libraries.

Simple Meaning
It is a technique which helps to inject dependent objects of a class.

Generic DI Video
Dependency Injection – YouTube

IOC DI with respect to .NET
In order to understand DI you need to understand what is IOC or Inversion of Control First
1. IOC ( Inversion of Control) explained in a simple way
2. Dependency Injection using Microsoft Unity Application block ( DI IOC) – 30 minutes training

NOTE: Before you watch any of the below videos watch the above three videos i found it to be a great foundation for understanding DI.

IOC can be achived in many ways and of that DI is one of the ways this diagram was the key for understanding DI atleast for me.

IOC

Unity DI with MVC3
ASP.NET MVC 3 with Dependency Injection and Inversion of Control (IoC) Container part 1
ASP.net MVC 3, DI with Ioc Unity Container part 2 – Populating Unity Container via Web.config

Unity DI with MVC5
Unity Dependency Injection on asp net mvc 5 tutorial Part I
Unity Dependency Injection on asp net mvc 5 tutorial Part II
Unity Dependency Injection on asp net mvc 5 tutorial Part III
Unity Dependency Injection on asp net mvc 5 tutorial Part IV
Unity Dependency Injection on asp net mvc 5 tutorial Part V

Castlewindsor DI with MVC5 and Entity Framework
Asp NET MVC 5, EF and castlewinsor DI PART I
Asp NET MVC 5, EF and castlewinsor DI PART II
Asp NET MVC 5, EF and castlewinsor DI PART III

Those who have Pluralsight can check the following
Practical IoC With ASP.NET MVC 4 – Pluralsight Training
*This covers Unity, Ninject and Castle Windsor

C# Design Strategies – Pluralsight Training
*This has sub sections which covers DI and IOC in chapter 3,4,5

Dependency Resolve
Using Unity to Resolve Instances based on a condition

Comparisons
Unity, Castle Windsor, StructureMap, Ninject – who is the best? | LinkedIn
Top 20 NuGet packages for IoC – NuGet Must Haves
IoC libraries compared | Elegant Code
List of .NET Dependency Injection Containers (IOC) – Scott Hanselman
What are pros and cons of using Unity vs other IoC containers? – Curah!

I need to personally try other frameworks to understand what suits my taste.

Most of the people have been against using XML configuration as its difficult to debug and later managing it becomes quite a hassle.