Autofac vs Ninject上下文绑定? [英] Autofac vs Ninject contextual binding?
问题描述
1)Autofac和Ninject,在上下文绑定中哪个更好?
1) Autofac and Ninject, which one is better in contextual binding?
2)使用Ninject,我可以绑定到特定名称空间中的类型:
2) With Ninject, I can bind to types in a specific namespace:
Bind<A>().To<B>().When(context =>
context.ParentContext.Binding.Service.Namespace == "MyProject.Common");
我可以使用Autofac做到这一点吗?
Can I do this with Autofac?
谢谢!
(对不起,我的英语)
推荐答案
在这两者中,只有Ninject提供此功能.
Of the two, only Ninject provides this functionality.
这是一个有用的功能,但是Autofac排除了它,以防止依赖于依赖项的其他Autofac特定功能的脆弱性不知道依赖项.
It is a useful feature but Autofac excludes it to prevent fragility in other Autofac-specific features that rely on the dependency being unaware of the dependent component.
如果您有可以从Autofac的这种行为中受益的场景,请随时发布它,我将尽力将其转换为Autofac的工作方式:)
If you have a scenario that would benefit from this kind of behaviour in Autofac, feel free to post it and I'll have a shot at translating it into Autofac's way of doing things :)
希望这会有所帮助, 尼克
Hope this helps, Nick
这篇关于Autofac vs Ninject上下文绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!