46

I'm new to DI and IoC and I'm trying to decide which IoC container to learn. I've seen several performance comparisons in which the three containers referenced seem to perform very well. However, I have found no feature comparisons that included Hiro or Simple Injector. The community for Autofac seems to be the largest, but Hiro and Simple Injector are blazingly fast in benchmarks and Simple Injector in particular claims to be very easy to learn. That said, I don't want to learn one and have to switch to another because the feature set is limited. For that reason I'm leaning towards Autofac since it is fairly mature and feature complete (good article here and here) as well as being one of the quickest IoC containers available. Has anyone had experience with at least two of the three of these containers? Can you offer any feature comparison?

joelmdev
  • 9,449
  • 8
  • 57
  • 82
  • You're missing a couple other big ones, StructureMap, Ninject, & Unity are all as popular or more so than AutoFac IMO – Brook Nov 18 '11 at 21:35
  • 25
    The performance of DI Containers is largely irrelevant. Unless you make applications that are vastly different from the 99% of applications being written on .NET, your performance bottlenecks *will* be elsewhere (I/O). Feature comparison can be found here: http://stackoverflow.com/questions/4581791/how-do-the-major-c-sharp-di-ioc-frameworks-compare/4583809#4583809 – Mark Seemann Nov 18 '11 at 21:52
  • @Brook I haven't read consistently good things about StructureMap or Unity. While I have read positive reviews of Ninject, it consistently benchmarks as one of the slowest available IoC containers. – joelmdev Nov 18 '11 at 21:58
  • 1
    I don't know what you define as "consistently good things", but personally StructureMap is my favorite due to it's pragmatism, it has some nice things built in that others don't, but it's not bloated, and very fast. Ninject is nice because it has fantastic plugin / nuget support. And as @Mark Seemann said, performance is the wrong way to judge a container. – Brook Nov 18 '11 at 22:03
  • 1
    @MarkSeemann I had found that question before asking this one. I think your comparison chart is great, but it lacks Hiro and Simple Injector. As I stated in this question it's hard to find feature comparisons that include Hiro and/or Simple Injector and the question you referenced is no exception. The only comparison posted in response to that question is benchmarking, not features. You seem to be very versed on this subject considering you wrote a book on it. Care to elaborate? – joelmdev Nov 18 '11 at 22:03
  • 2
    @Brook Although I'd like to get people's opinions on what their favorite IoC container is, that's not the format of SO and it's not the question I asked. Had I asked that this question would already be closed. I just want feature comparisons of the three containers that I mentioned in the title from individuals that have used at least two of them. That keeps me within the bounds of what's defined as a good question on this site ;) – joelmdev Nov 18 '11 at 22:12
  • 4
    Last time I looked at Hiro, I got the impression that it was mostly a proof of concept to prove that you could make a composition engine which would be just as fast as `new`ing things up by hand. Apart from being very fast, it has almost no 'features'. Regarding Simple Injector, I've no opinion... – Mark Seemann Nov 18 '11 at 22:35
  • On the subject on which .NET container is most popular, see this answer: http://stackoverflow.com/questions/6854445/what-is-the-current-state-of-ioc-containers-in-net/6856424#6856424 – Mark Seemann Nov 18 '11 at 22:37
  • 1
    @Mark you really should take a look at Simple Injector. You will like it :-p – Steven Nov 18 '11 at 23:09
  • @MarkSeeman that was a viable answer, I would repost as such! – joelmdev Nov 19 '11 at 18:02
  • You really ought to tag questions like this with the language or platform you're working with. There's not a lot of point in Java guys like me looking at this one! – Tom Anderson May 21 '12 at 17:35
  • @TomAnderson added "c#" tag for clarity, but the ".net" tag should have been a pretty good indication unless you're still using j# ;) – joelmdev May 21 '12 at 19:38
  • There wasn't a .net tag until i added it. – Tom Anderson May 22 '12 at 08:04
  • @TomAnderson I stand corrected! – joelmdev May 22 '12 at 13:41
  • @TomAnderson just realized that the reason that I didnt have language tags was due to the fact that I didnt have anymore room for tags, and I felt that IOC tag was more pertinent than a language tag. I'll meet you in the middle. – joelmdev May 22 '12 at 13:45
  • Thankyou. It can be hard to pick tags when there's a limit on the number of them. My rule of thumb is to have at least one very broad tag (usually a language), to steer away people who don't have any relevant expertise at all (like me!), then to use the rest for precision. – Tom Anderson May 22 '12 at 22:53
  • @TomAnderson for DI in Java, have a look at the Spring Framework if you havent already: http://www.springsource.org/ – joelmdev May 23 '12 at 17:57

1 Answers1

99

Let me start by saying that I'm the lead developer behind Simple Injector.

I agree with Mark that in most cases performance of a container isn't a problem. Still, some containers perform very poor at some points and it can be hard to intuitively sense what parts of the configuration can be problematic from a performance perspective. Most performance problems can be fixed by changing the configuration (changing registrations to singleton, adding caching, etc), no matter which container you use. At that point however it can get really complicated to configure a container. It's this complexity that we tried to solve with Simple Injector. I like to let others decide whether we succeeded (or whether having a DI container, or yet another DI container is even useful).

Performance however, was not even that high on my initial list when I started the project (simplicity was), but the (lock-free and Expression tree based) design allowed me to do optimizations that make it one of the fastest container in the field (while still being very feature rich and very extensible). In most cases you find the performance very close to newing up instances by hand.

This said, it still takes more time to learn dependency injection as a pattern than it takes to learn to work with a particular DI container (Mark's book can really help with both). A container – even Simple Injector – will not help you with understanding DI and SOLID (however, some of its restrictions try to push you to have a clean application design).

Simple Injector is pretty new (or late) in the DI scene. Because of this, there isn't much comparison between it and others (although there are some here and here) and number of users is limited compared to other frameworks but rapidly increasing (and according to an old poll from Roy Osherove, Simple Injector had a market share at that time of about 4%). That's a shame that Simple Injector isn't compared a lot, because it is capable of a lot (just look for instance at the advanced scenarios section in the documentation). Simple Injector is missing from the comparison you linked at (part 1 and part 2), so here's the feature list for Simple Injector (but do note that Simple Injector is added to one of the author's newer comparisons):

I have no idea what your requirements are, but I bet that Simple Injector can serve you for the lifetime of your project. If you're having trouble with it, just ask here at Stackoverflow.com or at the Simple Injector forum. The Simple Injector contributors and other enthusiasts will gladly help you. And don't forget that there are a bunch of Stackoverflow users that can help you with general DI problems.

Luke Girvin
  • 12,672
  • 8
  • 57
  • 79
Steven
  • 151,500
  • 20
  • 287
  • 393
  • Steven, thanks so much for chiming in! That helped a lot! – joelmdev Nov 19 '11 at 01:20
  • @Steven, can you please explain what you meant by SOLID in _A container -even the Simple Injector- will not help you with understanding DI and SOLID (however, some of its limitations force you to have a clean application design)._ – gligoran Feb 18 '13 at 21:00
  • 2
    @gligoran: I'm referring to the [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29) design principles (I forgot to include a link). Applying the SOLID principles is crucial in any reasonably sized piece of software where maintainability is an issue. – Steven Feb 19 '13 at 09:25
  • @Steven: Thanks for the explanation and the link. – gligoran Feb 19 '13 at 17:05
  • Careful, Simple injector does not support WebAPI out of the box. – Kugel Apr 28 '13 at 02:16
  • What is meant by Auto-mocking: Not included ? – Ray Feb 13 '14 at 22:19
  • @Ray, some containers can generate mock objects for you out-of-the-box in unit testing scenarios. This is not included in Simple Injector, but it is fairly easy to add. For info [here](http://blog.ashmind.com/2008/09/08/comparing-net-di-ioc-frameworks-part-2/) – Steven Feb 14 '14 at 07:07
  • 2
    Since version 2.4, Simple Injector has a support package for Web API. The documentation is [here](https://simpleinjector.codeplex.com/wikipage?title=Web%20API%20Integration) and the NuGet package is [here](https://www.nuget.org/packages/SimpleInjector.Integration.WebApi.WebHost.QuickStart). – Steven Jul 28 '14 at 08:52
  • @Steven does simple inject include delegate factories, or something else to avoid using a service locator when construction requires dynamic/variable parameters? Please say yes :) (https://code.google.com/p/autofac/wiki/DelegateFactories) – swestner Oct 08 '14 at 20:14
  • @swestner: You can [register a delegate](https://bit.ly/1CVPn3V) and auto-resolving Func delegates [can be added quite easily](https://bit.ly/1vWPZBM). – Steven Oct 08 '14 at 20:17
  • 1
    That's awesome! The project looks great, and I am looking forward to trying it out. Thanks! – swestner Oct 08 '14 at 20:29
  • 1
    @Steven Just FYI your SOLID link in your answer links back to this page. I think you meant to have it link to Wikipedia. – JHizzal Oct 27 '15 at 18:26
  • @JHizzal: Thanks for reporting. Fixed the link. – Steven Oct 27 '15 at 19:05