1

IoC is now built into ASP.NET 5 from the ground up. What is the advantage of using a third party IoC container like Autofac or Unity if any?

Would using a third party IoC container give better or worse performance? Are there other really useful features which the built in IoC container does not have?

I can no longer see a benefit of using one but want to make sure I'm not missing something.

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
  • 2
    The built-in container is pretty inexpensive. That said, that doesn't mean that something like LightInject wouldn't be faster and that unity wouldn't be (much) slower. The real benefit of a third part solution is features, not performance, and that of course is highly dependent on the IoC container itself. – David L Jul 20 '15 at 16:10
  • 2
    one thing I learned in this queston http://stackoverflow.com/questions/31492976/how-to-configured-nested-dependency-in-asp-net-5-di is that the built in DI cannot correctly wireup the decorator pattern and that was reason enough for me to want to use something else like autofac, however the current autofac seems to be only compatible with beta4 so during beta our options are limited. I'd say the built in one is fine until you need something it can't do for you. – Joe Audette Jul 20 '15 at 20:12

2 Answers2

6

Here is a list of benchmarks: http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison Autofac is relatively light-weight and has a lot of features. Ultimately other than performance there is no advantage over using the built in one if that's all your application requires. Same as using the built in testing suite vs nunit. It comes down to what you need to do with it and if it supports that feature and or performance critical.

Stephen Brickner
  • 2,584
  • 1
  • 11
  • 19
  • 2
    Not necessarily, it would need to be benchmarked as well to know for sure. In general if you don't know why you would need another IoC container besides the built in one then you don't need it. You would only switch to a 3rd party library when the need arises based on performance or feature needs. – Stephen Brickner Jul 20 '15 at 16:20
5

The built in IoC container is supposed to offer the bare minimum that the framework requires to work and to support dependency injection.

The advantage of using another container is that you might get access to features that are not available in the built-in container (property injection, named dependencies, configurable dependencies, etc.).

Also, there might be some perf benefits but you'd have to check that.

Victor Hurdugaci
  • 28,177
  • 5
  • 87
  • 103