Autofac vs Ninject contextual binding?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 04:19:47

问题


1) Autofac and Ninject, which one is better in contextual binding?

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");

Can I do this with Autofac?

Thanks!

(sorry for my English)


回答1:


Of the two, only Ninject provides this functionality.

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.

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



来源:https://stackoverflow.com/questions/4840275/autofac-vs-ninject-contextual-binding

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