Recently, the use of 6 of them ( Windsor , Unity , Spring.Net , Autofac , Ninject , StructureMap ) has appeared. I can offer a brief summary of each, our selection criteria and our final selection.
Note: we did not look at PicoContainer.Net, as one of our employees believed that the .Net port would be rather poor from the Java version. We also did not look at ObjectBuilder, since Unity is built on top of ObjectBuilder2 and is considered an excellent choice by default.
Firstly, I can say that they are more or less all very similar, and it really comes down to what really suits you best and your specific requirements. Our requirements included:
Requirements
- Constructor-based injection (we intend not to use injection of properties, fields or methods)
- Programmable Configuration ( Non XML)
- hierarchy of containers (one per application, for each request and per session, in order to more implicitly associate the component life cycle area with the container)
- component lifecycle management (for more granular coverage, e.g. transitional / single)
- from an interface to a type or a specific instance (e.g.
ILogger -> typeof(FileLogger) or ILogger -> new FileLogger() ) - creation of an advanced component / mechanism for creating a "mechanism" for initialization before / after
- proper disposal of
IDisposable components for container rupture. well-documented and / or online information available
Note: while performance was a requirement, it was not taken into account when choosing, because it seemed that all the containers examined were similar in accordance with this benchmark
Test
Each container was used in a typical Asp.Net web form project (since this was our target application type). We used one simple page with one simple user control, each of which inherits from the base page / base control, respectively. We used 1 container in BasePage for the container for the "for each request" area and 1 in global.asax for the "application" area and tried to link them together so that dependencies could be resolved from both containers.
Each web application shared a fictitious set of domain objects that simulate multi-level dependencies, the type of region (singleton / transient), as well as managed and unmanaged classes ( IDisposable ). Top-level dependency components were manually injected from methods on BasePage .
results
Windsor - meets all the criteria and has a good medical history, a community of bloggers and online documentation. Easy to use and probably the choice is defact. Advanced component creation using Factory. Combining individual created containers is also allowed.
Spring.Net is detailed and useless documentation and not obvious / simple for a programmable configuration. Did not support generics. Not chosen
Ninject - Ease of use with good clear documentation. A powerful set of functions that meets all our requirements, with the exception of container hierarchies, therefore, unfortunately, was not selected.
StructureMap is poorly documented, although it had a fairly expanded set of functions that meets all our requirements, but there was no built-in mechanism for the container hierarchy, although it could be hacked using for loops, see here The free lambda expression interface at first seemed a bit complicated, although it could be encapsulated.
Unity is well-documented, easy to use and meets all our selection criteria, and also has a simple extension mechanism to add the necessary mechanism for creating events / creating ads. Containers for children had to be created from the parent container.
Autofac is well documented and relatively easy to use, although the configuration of a lambda expression seems a little more complicated, but again can be easily encapsulated. Component detection is achieved using the “marking” mechanism, and all components are configured in the front using a creator that was a bit uncomfortable. Containers for children were created from the parent and assigned components from the "tag". Allowed general injection.
Conclusion
Our final choice was between Windsor and Unity, and this time we chose Unity because of its ease of use, documentation, expansion system and the fact that it is in a state of “production”.