I could have used Autofac!

Late last year I was working with Graeme Foster on a project which used ASP.NET MVC. We wanted the code base to be somewhat testable so when we built our controllers we were thinking about using some kind of dependency injection framework. Eventually, given the number of controllers we actually needed we decided that manual constructor injection would be the easiest way to go and just create a custom ControllerFactory.

This evening I’m reading through some of my feeds and I noticed this episode of .NET Rocks with Nicholas Blumhardt on the topic of Autofac. Just looking at the API it looks nice and tidy and minimal (which is what I want from my IoC container technology).

The cool thing is, it seems like it comes with a built in ControllerFactory. I haven’t used Autofac, but I think I will give it a shot next time I need a container.

P.S. The reason it triggered as I was reading my feeds is that I remember Graeme Foster saying that using Lambda expressions to initialise types in a container would be cool. Looks like Autofac supports something like this.

1 thought on “I could have used Autofac!

  1. Miguel Madero

    I’ve never used Autofac, but you gotta check Ninject, it’s really simple, but have easy to extend. Also supports MVC and it uses convention over configuration to automatically resolve bindings for controllers. It also uses a nice fluent interface and if you want to customize how a binding will get created you can use a callback converter, which is essentially a lamda that knows how to get the object.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s