0

There are many IOC containers for .net out there mainly MEF, Spring.net, Castle Windsor, Unity etc. Which is the most extensible and high performant? What should one consider when choosing a particular IOC container?

Thanks in adv

TrustyCoder
  • 4,749
  • 10
  • 66
  • 119
  • 1
    Without knowing exactly what your company needs, there's no way to make a recommendation. But for what its worth, Castle Windsor is pretty awesome and highly recommended. – Juliet Jun 19 '10 at 21:16
  • 2
    They're all pretty good. If you want a high-quality answer you should discuss the kind of app you're building (desktop? web?) the features you need (extensibility? AOP?) and the other frameworks you want to use (ASP.NET MVC? Prism? ...) Otherwise answers to this question are just "what I use is great" because the respondents have all picked a container based on their own needs :) – Nicholas Blumhardt Jun 20 '10 at 00:01
  • For a simple performance comparison of some of the most popular IOC containers you take a look at www.IOCBattle.com – MartinF Dec 21 '10 at 04:27
  • Here's a good benchmark that is kept up-to-date by the author: http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison – Steven Jan 14 '14 at 23:09

2 Answers2

1

For most projects, the performance of IoC containers is a non-issue, so it's a poor criterion to choose one over another unless you have very specific performance needs.

MEF has a different focus as a container. It's intended to be used as a plug-in repository (think runtime discovery) rather than traditional dependency injection where you mostly know statically what your components are and how they should be wired. This doesn't make it better or worse, it just has a different purpose.

For a somewhat Windsor-biased comparison see my answer to this similar question.

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
1

I think that reading the book "Dependency Injection in .NET" by Mark Seemann is the best way. Mark goes through several containers and is very good at all of them. http://www.amazon.com/Dependency-Injection-NET-Mark-Seemann/dp/1935182501/ref=sr_1_1?ie=UTF8&qid=1326500032&sr=8-1

I don't think that IOCBattle.com tells someone enough about real world use and best practices to rule out Ninject and Castle because they were much slower according to the results by MartinF who is the author of a little known IOC container.

Ninject is very easy to use and is in the Apress MVC 3 book. Unity is becoming popular as it is from Microsoft, and StructureMap is pretty nice (and has been favorable to many developers). They seem to perform pretty well. Unless someone with a heavy hit site has exposure to bench marking performance on each container or has done performance and load testing with concurrent users with a tool like JMeter.

I don't think some of these benchmarks accurately reflect the product. If your company must use the Microsoft stack, then hands down you must use Unity ( MEF lacks too many features for most situations). If you are "allowed" to use 3rd party / open source, then StructureMap, Ninject, Castle, and Autofac are the most popular. Again, Mark's book on DI has charts that break down which ones have auto-registration, xml configuration, lifetime.., this stuff becomes pretty important for an application.

Tom Stickel
  • 19,633
  • 6
  • 111
  • 113