什么是Container.GetAllInstances< T>在NInject中? [英] What is the equivalent of Container.GetAllInstances<T> in NInject?
问题描述
我正在使用NInject构建消息代理,我需要在实现Consumes的容器中找到所有实例,该接口将类标记为能够使用特定消息类型.
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.
是否支持这种情况?
推荐答案
内特的回答:
多分辨率(通过
GetAll
)是 目前还不是多态的.那意味着 它只会考虑绑定 从您指定的确切接口. 如果您这样做:
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>();
然后:
kernel.GetAll<IWorker>();
它将返回3个项目.但是,即使
如果IWorkerA
,IWorkerB
和
IWorkerC
实施IWorker
,
Ninject不会查看来自
当您询问时,从IWorkerA
到WorkerA
用于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
.
请参阅:
http://groups.google.com/group/ninject/browse_thread /thread/7b6afa06099bc97a#
这篇关于什么是Container.GetAllInstances< T>在NInject中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!