You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm converting an application from Unity to Ninject but I've hit an issue that I cannot find any doco on.
I have a class that has a constructor parameter that is an Array of a concrete class. Unity will inject an empty array if I haven't explicitly registered named instances.
With T[], List<T> and IEnumerable<T> multi injection takes precedence. If there is no Bindings for T (like Bind<T>()...) then ninject checks whether T is "self-bindable" (i.E. an instantiatable class), if so, it will create an instance of T.
So if T is an abstract class injecting an empty array is possible, too - because in that case T is not "self-bindable".
Short of making T abstract (or maybe changing it's ctors visibility, if that's possible?) the only remedies i can think of is adapting the binding of X where T[] is injected, either using ToConstructor, ToMethod, ToProvider - or mabe with an argument/parameter. Maybe you could also roll your own IParameter which resolves all the Ts by IResolutionRoot.GetAll.
I'm converting an application from Unity to Ninject but I've hit an issue that I cannot find any doco on.
I have a class that has a constructor parameter that is an Array of a concrete class. Unity will inject an empty array if I haven't explicitly registered named instances.
Ninject, on the other hand, will construct an instance of the concrete and give me an array with 1 element.
At the bottom of https://github.com/ninject/Ninject/wiki/Dependency-Injection-With-Ninject, it states that I should be able to inject 0..n.
Is an empty array only possible with interfaces ?
I cannot change the constructor signature, so is it possible to inject an empty array if no implementations of the concrete type are bound ?
The text was updated successfully, but these errors were encountered: