IoC containers, a comparison

Created by
Monday, August 15, 2016

Recently I have been in the market for a solid (excuse the pun) DI IoC container for a project I am currently working on. Using DI (Dependency Injection) is a design pattern I am fixated on and have nothing but great things to say about.

Although DI is a pattern that is present in all OOP languages and frameworks I will be focusing specifically on the .NET framework for this discussion.

What is an IoC container?

Put simply an IoC container is framework that a developer would use in their project to create dependencies and inject them where and wherever required. It creates objects based on requests and injects them when they are required. The container itself assists us in managing the dependencies. Finding a powerful IoC container can really help out with building a brilliant application. Adhering to the S.O.L.I.D principles is something I would highly recommend to any developer not currently using them.

IoC containers Compared

My issue with finding the best solution (like with most external additions) is to find the best possible IoC container at the start with and adhere to it from installation on. Today there are many great IoC containers out there, most of which are free.

First of all I want something well documented and popular. These two metrics to me are always vital. Having an external entity with support can really help out.

Second to documentation and popularity I am really looking for something that is open source and something that will allow me to tweak things as I please. It’s always very important to know the licences you are working with when you introduce external code.

I measure speed performance on both a single and multi threaded processes as per the great testing project created by Daniel Palme from Germany. His project is open source and free to test other IoC containers. In this situation a relatively simple test is performed. Objects with singleton lifetime are resolved. Daniels full tests cover 12 different problems of varying complexity. The best part is that his code is very well written and you can easily add your own tests to find the fastest performance based on what you want to achieve.

For my own performance testing I am using an Intel i7-4910MQ with CPU @2.90GHz along with 32.0GB RAM on a 64-bit OS. I am not on an SSD.

So let’s take a look at what I have found so far. In no particular order:

Container

Nuget

Source Code

Docs

Popularity

Speed (Single/Multi)

Licensed

Official Site

StructureMap

Yes

Yes

Yes

1,167,974

1356ms & 1287ms

Apache 2.0

Yes

Sprint.NET

Yes

No

Yes

4,133

975ms & 964ms

Apache 2.0

Yes

Autofac

Yes

Yes

Yes

2,501,836

706ms & 447ms

MIT License

Yes

Unity

Yes

Yes

Yes

4,033,916

2278ms & 1297ms

Apache 2.0

Yes

Ninject

Yes

Yes

Yes

3,402,210

5220ms & 3509ms

Apache 2.0

Yes

S2Container.NET

No

No

Yes

Unknown

 

Apache 2.0

Yes

HaveBox

Yes

No

Yes

3,637

57ms & 70ms

Apache 2.0

Yes

Castle Windsor

Yes

Yes

Yes

2,531,859

431ms & 343ms

Apache 2.0

Yes

Caliburn.Micro

Yes

Yes

Yes

11,437

681ms & 406ms

 

Yes

LinFu

No

Yes

Yes

Unknown

3291ms & 1743ms

LGPL3

No

Griffin

Yes

Yes

No

4,107

309ms & 213ms

GNU GPL

No

TinyIoc

Yes

Yes

No

64,556

450ms & 465ms

MIT License

No

LightCore

Yes

No

Yes

4,858

178ms & 154ms

 

Yes

Simple Injector

Yes

Yes

Yes

573,606

57ms & 54ms

Open

Yes

IfInjector

Yes

Yes

Yes

2,028

88ms & 102ms

BDS License

No

Abp.EntityFramework

Yes

Yes

Yes

101,297

 

MIT License

Yes

LightInject

Yes

Yes

Yes

95,796

49ms & 68ms

MIT License

Yes

Microsoft Extensions DependencyInjection

Yes

No

No

684,229

199ms & 223ms

Microsoft

No

Hiro IOC

Yes

No

No

3,584

143ms & 136ms

MIT License

No

Catel

Yes

No

Yes

Unknown

353ms & 380ms

MIT License

Yes

Dynamo.IoC

Yes

Yes

No

3,917

116ms & 143ms

 

Yes

fFastInjector

Yes

Yes

Yes

1,487

80ms & 83ms

BDS License

Yes

Funq

Yes

Yes

Yes

3,898

177ms & 136ms

Ms-PL

Yes

Grace

Yes

Yes

Yes

10,192

171ms & 166ms

Ms-PL

Yes

 

(2016-08-15)

 

Up to this point I have heard great things from Windsor and am very much considering using it. I would love to hear what others think and what they have experienced. If I have missed out on some other great IoC containers here please do let me know!

 

References:

http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison

http://www.dotnet-tricks.com/Tutorial/dependencyinjection/PcEb140413-What-is-IoC-Container-or-DI-Container.html

http://www.hanselman.com/blog/ListOfNETDependencyInjectionContainersIOC.aspx

http://nuget.org

0
Rating
1 2 3 4 5

Save

Saved

Report

Reported
Reasons
Cancel
0 comments