"List injection" in unity?

I have a project that will involve connecting to the same backend systems through the same interface; let's call it IBacksideProvider.

I would like to use Unity to implement these providers at runtime. The problem is, since we are talking about 1 ... n backend systems, I will need to register 1 ... n implementations of IBacksideProvider. Unity doesn't support this out of the box.

This blog post suggests that it can be done, however. I am wondering if anyone has done this or if there is an idea how to work with Unity in order to be able to do this. TIA.

+1


source to share


3 answers


Any reason why this won't work? http://msdn.microsoft.com/en-us/library/cc440943.aspx

To get a list of object instances from a container based on named registrations, use the ResolveAll method and provide a value for the object type (registration type). The ResolveAll method returns an IEnumerable generic list of non-standard (named) types that you can iterate over in your code to test each object.



IEnumerable<IMyObject> objects = myContainer.ResolveAll<IMyObject>();

      

+2


source


Unity supports array loading with version 1.2 which was released in November 2008 or so. This is the best you can do at this point in time without resorting to introducing a container of unity into your objects.



+1


source


LinFu.IOC supports IEnumerable <T> and IList <T> injections for constructors, properties, methods and even fields, all right out of the box. AFAIK, this is one of the few containers on this blog that supports list overflow in particular.

0


source







All Articles