Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Injector vs Hiro vs Autofac [closed]

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?

like image 837
joelmdev Avatar asked Nov 18 '11 21:11

joelmdev


1 Answers

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):

  • Framework: Simple Injector
  • Version: 3.0
  • License: MIT
  • Minimum dlls: 1
  • Size: 342 KB
  • Fluent: not needed, only programmatic
  • Automatic registration: included
  • Attribute usage: not included (but possible by extension)
  • XML usage: not supported
  • Property injection: yes (Opt-in).
  • Constructor injection: yes
  • Multiple constructors: not included, but extendable
  • Recursive dependency: meaningful error
  • Singleton: yes
  • Transient: yes
  • Other/Custom: yes, pluggable
  • Custom instances: supported
  • Open generics: included
  • Unregistered type resolution: yes
  • Auto-mocking: not included, but extendable.
  • Special features: Diagnostic Services, Registering decorators for generic types, partial open generics, conditional/contextual registration and performance. There are NuGet extension packages for lifestyles such as Web Request and Lifetime Scoping. The Expression based API allows adding support for almost any advanced scenario, such as interception (although the use of decorators is promoted).

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.

like image 79
25 revs, 3 users 100% Avatar answered Oct 05 '22 05:10

25 revs, 3 users 100%