是多个ninject绑定保证保持其绑定顺序

Aar*_*nHS 7 c# dependency-injection ninject

如果我注册:

Bind<IWeapon>().To<Sword>();
Bind<IWeapon>().To<Knife>();
Bind<IWeapon>().To<ChuckNorris>();
Run Code Online (Sandbox Code Playgroud)

然后检索通过:

IEnumerable<IWeapon> weapons = ServiceLocator.Current.GetAllInstances<IWeapon>();
Run Code Online (Sandbox Code Playgroud)

我保证绑定将始终以该顺序返回吗?

我尝试过,似乎确实如此,但这可能是偶然的.

Rem*_*oor 6

简短的回答:不,你不是!

更长的答案:当前实施保持顺序.但是在Ninject的未来版本中仍然会出现这种情况并不保证.此外,您不应该在IoC容器配置中具有此类业务规则.