Scott Hanselman

List of .NET Dependency Injection Containers (IOC)

March 14, '08 Comments [29] Posted in IOC | Learning .NET | Programming
Sponsored By

I'm trying to expand my mind around dependency injection in .NET (beyond the two frameworks I've personally used) and an starting to put together a list of .NET Dependency Injection Containers and IOC resources.

Here's what I've got so far. What am I missing?

What projects have I forgotten? Thanks!

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Friday, March 14, 2008 6:42:47 AM UTC
There are also the "hacked together when full blown ioc is either unneeded or cant be used for some managerial design decision".
People should realize that if they can't use one, the can always roll something simple to meet their needs.
Like when you want to have zero-dependency (but BCL).

Examples (shameless plug): Mine and Oren Eini's

Not great code, however usable.

Friday, March 14, 2008 6:47:15 AM UTC
And btw, Castle Windsor (as the rest of the Castle Project) is licensed under Apache License 2.0
Friday, March 14, 2008 7:10:00 AM UTC
There is also the Seasar DI Container, however I'm not sure what license it falls under.
Checkout http://s2container.net.seasar.org

Chris
Friday, March 14, 2008 7:34:56 AM UTC
PicoContainer.NET
(And remembering to double check the section of Windows Developer Power tools which has one of the best intros I've read on DI as well as a mention of the above :P)
Friday, March 14, 2008 8:13:15 AM UTC
Why on earth do Redmond not produce anything original.

Why do we need another IOC container aka Unity.

I love the CLR. I love the way it is evolving uniquely.

I am saddened by the 0 amount of innovation coming out of Redmond.

What have been their recent projects:

ASP.NET MVC - Read Monorail
Unity - Read the above.

I sincerely hop Unity is better than ObjectBuilder but why on earth would I choose it over Castle.

These guys should be ground breaking or Microsoft should be hiring some talent to set the standard.

I use open source because the tools are better. End of storty. If the MS tools were better I would switch instantly.

Paul Cowan
Friday, March 14, 2008 8:29:25 AM UTC
I didn't use ObjectBuilder a lot, but seems to me that it's not a full-blown IoC.
From my experience with it, it is "just" a DI framework, without the container.
Good enough that now the PnP build Unity :)
Friday, March 14, 2008 9:28:47 AM UTC
A great 4 part article on IoC by Simone Busoli can be found here

It gives a very good explanation of the power and usefulness of IoC.

Enjoy
Joe
Friday, March 14, 2008 11:08:11 AM UTC
Hi Scott,

Don't forget about The LinFu Framework, which has an IoC container of its own, not to mention some of the other following features:

* Aspect-Oriented Programming
* Dynamic Proxies
* Late Binding
* Mixins
* Universal Event Handling
* Closures with Lambda Arguments
* Duck Typing
* Design by Contract

If you get the chance, take a look at it and let me know what you think. Thanks!







Friday, March 14, 2008 11:28:27 AM UTC
Would be nice to see some example scenarios and how ioC framework each tackles it at code level.

[)amien
Friday, March 14, 2008 12:30:45 PM UTC
Scott,

This autofac project page holds some articles on autofac container and all the related links for the project.

Autofac IoC container fits really well into the usage scenarios of complex application and UI composition. And the core is really lighweight. That's the primary reason I fell in love with it. Others are: deterministic component disposal, proper component resolution within the nested scopes (that's what had driven me away from the Castle), elegant lambda syntax for complex registration scenarios.

Additionally ORM+IoC and xLim2 series might give you some insight on what could be efficiently done with this IoC container.

Please, feel free to ask questions, if you have any.

Best regards,
Rinat Abdullin
Friday, March 14, 2008 12:34:52 PM UTC
PS: context variables and transient (container-scoped components) represent common usage scenario in autofac. Resolving some transient component (registered in root container) in child container (with any depth of nesting) will fill in the dependencies from this child container first.
Friday, March 14, 2008 2:28:22 PM UTC
Thanks for mentioning Ninject in such great company. There'll be some new features coming in the near future now that I've been able to scrounge some more time to work on it. Hopefully some better documentation too. :)
Friday, March 14, 2008 3:05:23 PM UTC
Are there any IoC frameworks out there for the Compact Framework? I have spent some time looking but havn't found anything yet. This seems to leave two options, roll my own from scratch, or pick one of the existing IoC frameworks out there and try to port it over. I would love to hear opinions on which framework might be the easiest to port.
Friday, March 14, 2008 4:25:55 PM UTC
I wrote a simple (and free) service locator for DI that is described at here, and the code is available for download. It's a relatively simple implementation, but if you're new to new to DI/IoC, you might be interested in seeing how it works.
Friday, March 14, 2008 5:20:54 PM UTC
Hey Scott, I look forward to see what kind of conclusions you come to. I am still meaning to play around w/ some of the other frameworks you mention, however, StructureMap is my current IoC framework of choice. I wrote a Simple Dependency Injection with StructureMap tutorial to hopefully help anyone who has not used it before. Regards!
Friday, March 14, 2008 6:13:05 PM UTC
Some updates and an answer to a question from above:

I didn't work on the original ObjectBuilder; that was Scott, Brad, & Peter Provost. Unity is being built on top of OB; OB : Unity <-> Castle Microkernel : Castle Windsor. Also, Unity isn't quite released yet; we've got a week or so to go to 1.0.

@Adam Salvo:

You might want to check out the Mobile Client Software Factory at http://msdn2.microsoft.com/en-us/library/aa480471.aspx. The main reason is that the team did a lot around DI with objectbuilder on the mobile platform. They discovered that reflection is HELLISHLY expensive on WinCE, so they wrote a preprocessing tool called obgen that does the reflection required at compile time, and generates the code to assemble objects. Might be worth checking out.
Friday, March 14, 2008 6:50:32 PM UTC
I have an open source framework called SharpCore hosted on CodePlex that has an IoC implementation. It was written mainly as an exercise in understanding what makes them work; plus, it was a lot of fun to write!

You can check it out here: http://www.codeplex.com/SharpCore
Friday, March 14, 2008 8:08:58 PM UTC
You missed out XAML :-) It's an object builder language - and therefore a dependency injection system.
RichB
Friday, March 14, 2008 9:47:27 PM UTC
@Adam: I wrote a version of Ninject for the .NET compact framework for a project at work. My plan is to clean it up and release it along with the "full" fx version. I can send it to you if you like.
Saturday, March 15, 2008 2:06:28 AM UTC
<plug type="shameless">
I just published an article on DI/IoC in the March 2008 issue of MSDN Magazine. The advanced examples use Windsor, but the point of the article is to explain the underlying concepts. So if you are wondering why DI/IoC matters, go read Loosen Up: Tame Your Software Dependencies for More Flexible Apps. In the article, I roll a simple DIY IoC in about the same number of lines as Oren's or Ken's. Just another example of how you can easily use DI/IoC concepts in your application even if you can't use a full-fledged IoC framework for political reasons.
</plug>
Saturday, March 15, 2008 3:12:55 AM UTC
Thanks for the links. This is an interesting topic to delve into!
Saturday, March 15, 2008 3:24:59 AM UTC
@Nate: I'd loved to take a look at Ninject for the compact framework. You can send it to adam at salvoz dot com, or let me know when you release it. Thanks.

@Chris: Thanks for the heads up on the mobile client software factory. I've see some references to it before but havn't looked at it in depth yet.
Saturday, March 15, 2008 12:34:51 PM UTC
Hi Scott,

Thanks for the comprehensive listings. Could you link to the Spring.NET home page, instead of our training page?

<editorial>I don't think it would be inaccurate to say that Spring.NET is also very well documented and widely used.</editorial>

Cheers,
Mark
Saturday, March 15, 2008 11:22:58 PM UTC
LinFu
* Licensed under Lesser GPL
* Written by Philip Laureno

Dude, you spelled my last name wrong--it's "Laureano", not "Laureno"...
Sunday, March 16, 2008 7:18:56 AM UTC
Thanks for the link, Scott.

Looking over this 'complete' list reminds me of Ayende's concern that DI containers are too often evaluated only on the merits of their DI capabilities - I take my hat off to any reviewer who can achieve even that much in such a broad field of libraries!

He's right, of course - the more interesting features usually only present themselves once you're into the thick of building an application. I don't think they're really make-or-break though.

My advice to anyone reading this and wondering where to start is not to focus too much on the libraries - dependency injection is a powerful coding style that will make a much bigger impact on the architecture of an application than the particular container will. Once you've mastered dependency injection itself you'll have a much clearer idea of the features you want from a container.

Interesting list, looking forward to hearing some more along this theme :)

Nick
Wednesday, March 19, 2008 3:11:47 PM UTC
Scott, out of curiosity, so far which have you to bee easiest/best to use.
RhysC
Wednesday, March 19, 2008 3:14:33 PM UTC
ok my engerish is not so good...

Scott, out of curiosity, so far, which of the afore mentioned IoC containers have you found to be the easiest/best to use?
RhysC
Saturday, April 26, 2008 9:26:21 PM UTC
@Adam: I have writen a lightweight IoC container that works under .NET Compact Framework 2. You can check it out at compactcontainer.googlecode.com
Monday, May 12, 2008 12:43:17 PM UTC
Hi Scott,

You could add our freshly released IoC container. Winter4net is fast, compact and scalable lightweight .NET inversion of control (IoC, dependency injection) container.
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.