Dependency Injection Frameworks


“The Unity Container (Unity) is a lightweight, extensible dependency injection container. It facilitates building loosely coupled applications”

This was very simple to setup for an ASP.NET MVC project (Unity.Container, Version=


public static void RegisterComponents()
     var container = new UnityContainer();
     container.RegisterType<IClientRepository, ClientRepository>();
     DependencyResolver.SetResolver(new UnityDependencyResolver(container));


This was useful in a legacy Web Forms application (Autofac, Version= however it would have worked just as well in the MVC application I used Unity in.


protected override void Load(ContainerBuilder builder)
   builder.Register(db => new NpgsqlConnectionFactory(ConnectionName)).As<IDatabaseConnectionFactory>();
   //default ctr
   builder.Register(cm => new ClientRepository()).As<IClientRepository>();

   //ctr with connection param
   .WithParameter(ConnectionName, new NpgsqlConnectionFactory(ConnectionName));


These 3 are listed inĀ Professional Test Driven Development with C#: Developing Real World Applications with TDD

  • Structure Map
  • Windsor

Leave a Reply