Sunday, October 21, 2012

DI Patterns :: in ASP.NET MVC - Introduction

As innovative developer, I always loved to learn and implement design principles and patterns. DI patterns are one of it.

DI Patterns as well defined by "Mark Seemann" in his book "Dependency Injection in .NET":
It is set of design principles and patterns which enable to write loosely coupled code.  

I bet, you would love to read "How to explain Dependency Injection to a 5-year old" (unfortunately closed article) article on the stackoverflow.

ASP.NET MVC in its way, has provided various ways to write loosely coupled  web applications. In the ASP.NET MVC, we can use DI patterns by

  1. Writing our own Controller Factory by Implementing IControllerFactory interface
  2. Writing custom Controller Factory by  deriving from DefaultControllerFactory
  3. Writing custom Dependency Resolver by implementing IDepedencyResolver interface.
  4. Writing custom ControllerActivator by implementing IControllerActivator.
 DI containers is library which provides DI functionality. There are plenty of DI containers available and can be used based on our needs. Ninject, Windsor, Spring.NET, Unity are few of them.

I will keep posting more on the above mentioned ways to use DI patterns in ASP.NET MVC.