1

I've got a project coming up that will involve connecting to one to many backend systems through the same interface; let's call it IBacksideProvider.

I'd like to use Unity to inject these providers at runtime. The problem is that since we're talking about 1...n backend systems, I'd 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'm wondering if anybody has done this or has an idea how to go about working Unity so as to be able to do this. TIA.

3 Answers3

2

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

To retrieve a list of object instances from the container based on named registrations, use the ResolveAll method and specify a value for the object type (the registration type). The ResolveAll method returns an IEnumerable generic List of the non-default (named) registered types that you can iterate through in code to examine each object.

IEnumerable<IMyObject> objects = myContainer.ResolveAll<IMyObject>();
Szymon Rozga
  • 17,971
  • 7
  • 53
  • 66
1

Unity supports array injection as of version 1.2, which was released back in November 2008, or so. This is the best you can do at the moment, without resorting to injection of unity container into your objects.

0

LinFu.IOC supports IEnumerable<T> and IList<T> injection for constructors, properties, methods, and even fields, all right out of the box. AFAIK, it's one of the very few containers on that blog that actually supports list injection, among other things.

plaureano
  • 3,139
  • 6
  • 30
  • 29