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?
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?
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
, andIWorkerC
implementIWorker
, Ninject will not look at bindings fromIWorkerA
toWorkerA
when you ask forIWorker
.
See :
http://groups.google.com/group/ninject/browse%5Fthread/thread/7b6afa06099bc97a#
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.