Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of Container.GetAllInstances<T> in NInject?

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?

like image 804
pnschofield Avatar asked Sep 08 '09 15:09

pnschofield


Video Answer


1 Answers

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_thread/thread/7b6afa06099bc97a#

like image 65
Romain Verdier Avatar answered Nov 21 '22 00:11

Romain Verdier