This project is read-only.

RegisterAll and constructor injection (IEnumerable<T> vs T[])

Jun 25, 2013 at 11:09 AM
Hi,

This is more a curiosity question than an issue.

RegisterAll enables constructor injection with a IEnumerable<Service> parameter, but not a Service[] parameter. I'm sure you have good reason to do this and I'd love to know why.

I read the previous discussion https://simpleinjector.codeplex.com/discussions/360001 and I wonder if it could be tied.

I discovered from another project that other IoC containers (Autofac, Ninject, and StructureMap) prefer inject all instances of a service via an array parameter. I'm very familiar with Simple Injector and it would be nice if its behavior could be "compatible". In fact, this other project is developed with this behavior in mind, so I can't change the parameter type for an IEnumerable in place of arrays.
As a consequence, the registration in Simple Injector is a bit more complicated because I have to register these objects with a delegate.

Thank you for this top product. I use Simple Injector in almost all my projects.
Jun 25, 2013 at 12:18 PM
Such feature was left out, because:
  • Depending on a collection of types should be rather exceptional. Instead of injecting collections in many places, you would typically be better of with injecting a composite (that depends on a collection).
  • Simple Injector's design goals are to be performant by default. Resolving an array will always result in the allocation of a new array (since arrays are mutable, they can't be cached). This is an extra hidden cost.
  • The extendability mechanisms of Simple Injector make it easy to add such feature yourself.
Marked as answer by dot_NET_Junkie on 3/2/2014 at 10:44 AM
Jun 25, 2013 at 8:03 PM
  1. Indeed, my scenario seems to be composite-based.
  2. I had this in mind, as a good reason.
  3. Good point. I had not looked enough in the (very good) documentation.
Thanks for your answer.