The Best IoC Container?

As I previously mentioned in my post “The Best JavaScript Library“, I am in the process of developing an application/writing a book.  I will be using asp.net MVC and a TDD approach to the application and book.  As I have done with the JavaScript framework selection, I decided to look around and evaluate/review my options for an Inversion of Control (IoC) Container.

Naturally, my research lead me to a post by Scott Hanselman (see it here) which lists some of the more popular IoC and dependency injection frameworks out there.

Spring.Net

I started of looking at Spring.Net and was very impressed by its features, samples/tutorials and documentation but it felt like it would be too much for this project and the learning curve seemed somewhat steep.  Its configuration syntax also looked very verbose.  But if you want to learn more there is a good article over here.

Castle Windsor

It looked easier to learn/use than spring.net but there getting started section was incomplete even though Scott says that it is well documented.  So that was a little discouraging.

Autofac

I really liked there syntax and looked really easy to use and figure out, but the documentation was very limited.  It was just a bunch of wiki pages in Google Code.  Though, they did have instructions on how to integrate it with MVC

StructureMap

Initially, I learned about structure map from a post by Phil Haack’s and I kind of liked it right away.  It was easy to pick up and figure out and Phil’s example helped to get me started quickly.  I checked there website and it has an impressive list of features and is well documented.

PostSharp

PostSharp is really cool but is not an IoC container.  It is a policy injector and a really easy way to do Aspect Oriented Programming (AOP).  Rather than trying to explain what exactly it does and screw it up, take a look at the “About PostSharp” page.  Even better check out this “getting started” walkthrough – you will be very impressed.

Must Pick One

I know there is a lot more IoC containers out there (which I glanced over), but these were sufficient for me.  Initially, I thought about using AutoFac but when I started to actually use it and ran into some issues, the documentation was not helpful at all.

I have decided to go with StructureMap as my IoC Container and dependency injector.  I might also use PostSharp to implement logging and tracing as aspects – there is no cleaner way.

Helpful Links

For a good explanation of IoC Containers and the Dependency Injection patter, read this article by Martin Fowler.

This also a good explanation that might help you understand IoC Containers.

You should definilty take a look Matthew Podwysocki’s comparison of the different IoC containers out there and their different (or rather similar) configuration and syntax.

Books you must Read

Applying Domain-Driven Design and Patterns

And Martin Fowler’s indispensable reference for software patterns Patterns of Enterprise Application Architecture

Validate my Choice

What do you think of my choice?  Does it really matter which one I go with?  Do you prefer a different IoC container and why?

Time to choose a unit testing framework… I love choices!!!

[poll id=”3″]

Advertisements

0 thoughts on “The Best IoC Container?

  1. Of course I’m biased (I sit next to the creator/maintainer every day), but +1 on StructureMap.Windsor is a good choice, too. Don’t know much about Autofac, but I’ve heard a few good things about it.Avoid Spring.NET, though. I started out with it, it was easy to get going, but it falls apart on IoC features very fast.

    Like

  2. Of course I’m biased (I sit next to the creator/maintainer every day), but +1 on StructureMap.

    Windsor is a good choice, too. Don’t know much about Autofac, but I’ve heard a few good things about it.

    Avoid Spring.NET, though. I started out with it, it was easy to get going, but it falls apart on IoC features very fast.

    Like

    • I don’t have anything specific. But a small suggestion, I wasn’t sure whichversion to use. One version said Release 1.2.7 for .net 2.0 and the othersaid Release 1.2.7… Which .net version is that one? 1? 1.1? 3.0? 3.5? Iassumed it was 3.5 and downloaded that one.Also when I tried to integrate it into my asp.net mvc project according toyour wiki on MvcIntegration, I am supposed to referenceAutofac.Integration.Web.Mvc.dll – which is no where to be found and therewas no link to download it anywhere…So, I figured if things are going to be that hard to get started and findthings, they will be a lot harder when I have a serious issue down the road.I hope that helps.PS: I am willing to give it another shot if you can point me in the rightdirection.

      Like

  3. Hi Emad,Thanks for the suggestions. I've updated the name of the download to “Release 1.2.7 for .NET 3.5” (your assumption was correct.)Regarding Autofac.Integration.Web.Mvc.dll – it is in the /bin folder contained within the zip file (featured on the front page – should have been the file you downloaded.) All of the Autofac assembiles should be included in the same download.I'd love to hear how you go if you have another shot. The http://groups.google.com/group/autofac group is always a good place to ask any questions you come up with.Cheers!Nick

    Like

  4. I don't have anything specific. But a small suggestion, I wasn't sure whichversion to use. One version said Release 1.2.7 for .net 2.0 and the othersaid Release 1.2.7… Which .net version is that one? 1? 1.1? 3.0? 3.5? Iassumed it was 3.5 and downloaded that one.Also when I tried to integrate it into my asp.net mvc project according toyour wiki on MvcIntegration, I am supposed to referenceAutofac.Integration.Web.Mvc.dll – which is no where to be found and therewas no link to download it anywhere…So, I figured if things are going to be that hard to get started and findthings, they will be a lot harder when I have a serious issue down the road.I hope that helps.PS: I am willing to give it another shot if you can point me in the rightdirection.

    Like

  5. Hi Emad,Thanks for the suggestions. I've updated the name of the download to “Release 1.2.7 for .NET 3.5” (your assumption was correct.)Regarding Autofac.Integration.Web.Mvc.dll – it is in the /bin folder contained within the zip file (featured on the front page – should have been the file you downloaded.) All of the Autofac assembiles should be included in the same download.I'd love to hear how you go if you have another shot. The http://groups.google.com/group/autofac group is always a good place to ask any questions you come up with.Cheers!Nick

    Like

  6. Pingback: Ninject: Killer IoC | Emad Ibrahim

  7. Pingback: Mocking and Dependency Injection in ASP.NET MVC | Emad Ibrahim

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s