What's the difference between .ToConstructor and .ToMethod in Ninject 3?

耗尽温柔 提交于 2019-11-30 07:54:21

The first case behaves like To<MyService>() except that you explicitly select the constructor. This means the context is passed through MyService and you can use conditions for IFoo and IBar or one of their dpependencies where in the second case you get a new context for IFoo and IBar and you will not know that they are injected into MyService.

e.g.

Bind<IFoo>().To<FooA>().WhenInjectedInto<MyService>();
Bind<IFoo>().To<FooB>().WhenInjectedInto<MyOtherService>();

will not work in the second case.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!