gpt4 book ai didi

dependency-injection - NInject 中的 Container.GetAllInstances 等价物是什么?

转载 作者:行者123 更新时间:2023-12-04 18:54:19 25 4
gpt4 key购买 nike

我正在使用 NInject 构建一个消息代理,我需要在容器中找到所有实现 Consumes 的实例,这是一个将类标记为能够使用特定消息类型的接口(interface)。

是否支持此场景?

最佳答案

内特的回答:

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.



看 :

http://groups.google.com/group/ninject/browse_thread/thread/7b6afa06099bc97a#

关于dependency-injection - NInject 中的 Container.GetAllInstances<T> 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1394697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com