ASP MVC +城堡 + nHibernate如何连接?
连接asp mvc + 温莎城堡 + nhibernate 的最佳方式是什么?
我有一个存储库,它被注入到我的控制器构造函数中。
这是执行此操作的良好且正确的方法吗:
Component.For<ISessionFactory>().UsingFactoryMethod(()=> CreateSessionFactory() ).LifeStyle.Singleton,
Component.For<ISession>().UsingFactoryMethod ( k=>k.Resolve<ISessionFactory>().OpenSession()).LifeStyle.PerWebRequest
然后将 ISession
注入存储库构造函数?
交易和处置会话怎么样?
感谢您的帮助!
What is the best way to connect asp mvc + castle windsor + nhibernate?
I have repository which is injected into my controller constructor.
Is this a good and correct way of doing this :
Component.For<ISessionFactory>().UsingFactoryMethod(()=> CreateSessionFactory() ).LifeStyle.Singleton,
Component.For<ISession>().UsingFactoryMethod ( k=>k.Resolve<ISessionFactory>().OpenSession()).LifeStyle.PerWebRequest
and then just inject ISession
into repository constructor ?
What about transactions and disposing session ?
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MVC + Castle + NHibernate?最好的方法是使用 S#arp 架构,而不是重新发明轮子。
完整的示例可以在此处找到。
MVC + Castle + NHibernate? The best way would be to use S#arp Architecture instead of reinventing the wheel.
A full example can be found here.
我为你和任何其他想要这样做的人创建了一个设施。
https://github.com/haf/Castle .Facilities.NHibernate/wiki/NHibernate-Facility---快速启动
Nuget:
Castle.Facilities.NHibernate
如果你找到了请告诉我这是值得的。这是非常简约的。只需在处理当前工作单元的命令处理程序周围放置一个 [Transaction] 即可。我不建议使用不同交易的多种服务。因此,我在温莎创造了一种新的生活方式,称为“每笔交易”。
我可以在城堡邮件列表上为您提供更多帮助。
I created a facility for you and anyone else who wants to do this.
https://github.com/haf/Castle.Facilities.NHibernate/wiki/NHibernate-Facility---Quick-Start
Nuget:
Castle.Facilities.NHibernate
Tell me if you find it worthwhile. It's very minimalistic. Just put a [Transaction] around the command handler that is handling the current unit of work. I don't recommend multiple services with disparate transactions. As such, I created a new lifestyle in Windsor called per transaction.
I can give you more help on the castle mailing list.