使用WhenInjectedExactlyInto和默认绑定时,绑定顺序很重要吗?

时间:2019-05-07 15:39:09

标签: ninject

对于多个Ninject模块,我最终对特定接口具有如下所示的绑定顺序:

Kernel.Bind<ILogger>().To<Logger>().WhenInjectedExactlyInto(typeof(TroubleshootingLogger), typeof(RegularAndStashLogger), typeof(LogStashLogger), typeof(KafkaSendClient));
Kernel.Bind<ILogger>().To<TroubleshootingLogger>();
Kernel.Bind<ILogger>().To<RegularAndStashLogger>().WhenInjectedExactlyInto<ProcessConfiguration>();

我的问题是,当我为ProcessConfiguration的实例调用内核时,是否将其注入故障排除日志记录器(默认绑定)或RegularAndStashLogger(确切的绑定)?

1 个答案:

答案 0 :(得分:0)

我继续并建立了一个小型测试程序来自己确定(我承认我应该先这样做)。

事实证明,Ninject确实会先检查所有“ WhenInjectedExactlyInto”绑定,然后才退回到默认绑定。

程序(取决于要运行的Ninject,呵呵):pastebin.com/9Kpsb25h

相关问题