Scott Hanselman

List of .NET Dependency Injection Containers (IOC)

March 14, 2008 Comment on this post [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. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
March 14, 2008 10:42
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.

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

March 14, 2008 11:34
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)
March 14, 2008 12:13
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.

March 14, 2008 12:29
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 :)
March 14, 2008 13:28
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
March 14, 2008 15:08
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!







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

[)amien
March 14, 2008 16:30
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
March 14, 2008 16:34
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.
March 14, 2008 18:28
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. :)
March 14, 2008 19:05
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.
March 14, 2008 20:25
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.
March 14, 2008 21:20
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!
March 14, 2008 22:13
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.
March 14, 2008 22:50
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
March 15, 2008 0:08
You missed out XAML :-) It's an object builder language - and therefore a dependency injection system.
March 15, 2008 1:47
@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.
March 15, 2008 6:06
<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>
March 15, 2008 7:12
Thanks for the links. This is an interesting topic to delve into!
March 15, 2008 7:24
@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.
March 15, 2008 16:34
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
March 16, 2008 3:22
LinFu
* Licensed under Lesser GPL
* Written by Philip Laureno

Dude, you spelled my last name wrong--it's "Laureano", not "Laureno"...
March 16, 2008 11:18
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
March 19, 2008 19:11
Scott, out of curiosity, so far which have you to bee easiest/best to use.
RhysC
March 19, 2008 19:14
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
April 27, 2008 1:26
@Adam: I have writen a lightweight IoC container that works under .NET Compact Framework 2. You can check it out at compactcontainer.googlecode.com
May 12, 2008 16:43
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.