views:

100

answers:

2

I'm building a message broker with NInject, and I need to find all instances in the container that implement Consumes, an interface that marks the class as being able to consume a particular message type.

Is this scenario supported?

+4  A: 

Answer from Nate:

Multi-resolution (via GetAll) is currently not polymorphic. That means that it will only consider bindings from the exact interface you specify. If you do this:

kernel.Bind<IWorker>().To<WorkerA>();
kernel.Bind<IWorker>().To<WorkerB>();
kernel.Bind<IWorker>().To<WorkerC>();

And then:

kernel.GetAll<IWorker>();

It will return 3 items. However, even if IWorkerA, IWorkerB, and IWorkerC implement IWorker, Ninject will not look at bindings from IWorkerA to WorkerA when you ask for IWorker.

See :

http://groups.google.com/group/ninject/browse%5Fthread/thread/7b6afa06099bc97a#

Romain Verdier
+1  A: 

If you if you don't have the polymorphic situation as discussed in the thread that is referenced by Romain's answer, then you shouldn't have any issues as long as you are using Ninject 2. Ninject 1.x did not include this sort of support.

Peter Meyer