本文介绍了这个转换温莎城堡Installer将Ninject登记所有存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这在我的MVC2应用程序,但我认为,作为其变得越来越流行,我可能转移到Ninject和温莎城堡似乎一点点在复杂的。
我怎么会做这样的事情在Ninject不过?
也许温莎城堡是比较发达的,我应该坚持下去。
container.Register(AllTypes.FromThisAssembly()
。凡(类型=> type.Name.EndsWith(库))
.WithService.DefaultInterface()
.Configure(C => c.LifeStyle.PerWebRequest));
解决方案
您想做可以用Ninjec.Convention扩展做什么。
I have this in my MVC2 app but I think I might move to Ninject as its becoming more popular and Castle Windsor seems a tad over complicated.
How would I do something like this in Ninject however?
Maybe Castle Windsor is more developed and I should stick with it.
container.Register(AllTypes.FromThisAssembly()
.Where(type => type.Name.EndsWith("Repository"))
.WithService.DefaultInterface()
.Configure(c => c.LifeStyle.PerWebRequest));
解决方案
What you want to do can be done with the Ninjec.Convention extension.
https://github.com/ninject/ninject.extensions.conventions
http://innovatian.com/2009/09/conventions-based-binding-with-ninject-2-0-2/
http://innovatian.com/2010/02/ninject-extensions-conventions-preview/
这篇关于这个转换温莎城堡Installer将Ninject登记所有存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!