55.//TODO: fix line above; the list is not being picked up in the target.
56.// JustMock seems keen on giving us a list with one and only one item in it, rather than
57.// what we've registered above.
The registration on line 51 seems to be ignored. Is there something else I should be doing?
3 Answers, 1 is accepted
answered on 23 Jul 2014, 09:38 AM
NInject handles the injection of collections in a special case. Instead of treating it as a regular dependency type, it instead gathers all dependencies of the same type as the collection element types, creates a collection, fills it with these dependencies and passes this collection to the constructor.
You can employ this behavior by binding the individual IWorker instances, like so:
var providersArg = new ConstructorArgument("workers", providers);
The above specifies that while resolving the "Service" instance, the constructor argument named "workers" should be given the "providers" instance.
Note that this mechanism works besides the .Instance property of the container. If you then get the value of the Instance property, it will construct a new instance of the Service class with the "workers" argument populated through multi-injection. You should be careful not to mix the usage of the two mechanisms in a given container instance.
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.