views:

189

answers:

3

I'm relatively familiar with the concepts of DI/IOC containers having worked on projects previously where their use were already in place. However, for this new project, there is no existing framework and I'm having to pick one.

Long story short, there are some scenarios where we'll be configuring several implementations for a given interface. Glancing around the web, it seems like using any of the mainstream frameworks to selectively bind to one of the implementations is quite simple.

There are however contexts where we'll need to run ALL the configured implementations. I've scoured all the IOC tagged posts here and I'm trying to pour through documentation of the major frameworks (so far looking at Unity, Ninject, and Windsor), but docs are often sparse and I've not the time to inspect source for all the packages.

So, are there any mainstream IOC containers that will allow me to bind to all the configured concrete types for one of my services?

A: 

So I somehow missed this my first pass looking through Unity somehow...but I'll answer my own question.

Unity has precisely what I wanted. http://msdn.microsoft.com/en-us/library/cc440943.aspx

Also, for anyone else doing the IOC hunt and dance like me, this link proved to be invaluable. http://blog.ashmind.com/index.php/2008/09/08/comparing-net-di-ioc-frameworks-part-2/

bakasan
+1  A: 

One thing that caught me the first time I was trying to resolve all implementations of a registered type was that un-named (default) type registrations will not be returned when you call ResolveAll(). Only named instances are returned.

So:

IUnityContainer container = new UnityContainer();
container.RegisterType<IMyInterface, MyFirstClass>();
container.RegisterType<IMyInterface, MySecondClass>("Two");
container.RegisterType<IMyInterface, MyThirdClass>("Three");

var instances = container.ResolveAll<IMyInterface>();

Assert.AreEqual(2, instances.Count, "MyFirstClass doesn't get constructed");
Jeremy Wiebe
A: 

Believe me Unity is not what you want. IMHO it's the worst choice because of its verbosity, lack of important features and strange behavior that violates the principle of the least surprise (like the example Jeremy gave).

If I were you I'd pick Castle Winsor

Krzysztof Koźmic