当我有两个范围重叠的 Ninject 绑定规则时,我有两个问题要解决,一个比另一个更具体。他们是:
- Ninject 在构造对象时会自动选择最具体的绑定规则吗?
- 我是否必须将更具体的规则放在更一般的规则之前,以便在绑定规则块中出现顺序?
考虑以下两个规则作为示例:
// The more specific (constrained) rule that is
// constrained to a particular class being constructued.
Bind<ISomeInterface>().To<SomeOtherClass>()
.WhenInjectedInto(typeof(ParticularClassBeingConstructed));
// The more general rule for any ISomeInterface match.
Bind<ISomeInterface>().To<SomeClass>();