ASP MVC +城堡 + nHibernate如何连接?

发布于 2024-11-08 15:49:23 字数 459 浏览 6 评论 0原文

连接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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇到 2024-11-15 15:49:23

MVC + Castle + NHibernate?最好的方法是使用 S#arp 架构,而不是重新发明轮子。

发音为“Sharp Architecture”,这个
是坚实的架构基础
用于快速构建可维护的网络
利用 ASP.NET 的应用程序
MVC 框架与 NHibernate。这
寻求的主要优势
使用任何架构框架都是
减少必须编写的代码
在提高质量的同时
成品。框架应该能够
开发人员花费很少的时间
基础设施细节,同时允许
他们将注意力集中在
领域和用户体验。
因此,S#arp 架构
遵守以下关键
原则:

  • 专注于领域驱动设计
  • 松耦合
  • 预配置的基础设施
  • 开放式演示

这样做的总体目标是让
开发商无需担心
应用程序“管道”并花费
他们的大部分时间都花在增加价值上
专注于业务的客户
逻辑和开发丰富的用户
经验。

完整的示例可以在此处找到。

MVC + Castle + NHibernate? The best way would be to use S#arp Architecture instead of reinventing the wheel.

Pronounced "Sharp Architecture," this
is a solid architectural foundation
for rapidly building maintainable web
applications leveraging the ASP.NET
MVC framework with NHibernate. The
primary advantage to be sought in
using any architectural framework is
to decrease the code one has to write
while increasing the quality of the
end product. A framework should enable
developers to spend little time on
infrastructure details while allowing
them to focus their attentions on the
domain and user experience.
Accordingly, S#arp Architecture
adheres to the following key
principles:

  • Focused on Domain Driven Design
  • Loosely coupled
  • Preconfigured Infrastructure
  • Open Ended Presentation

The overall goal of this is to allow
developers to worry less about
application "plumbing" and to spend
most of their time on adding value for
the client by focusing on the business
logic and developing a rich user
experience.

A full example can be found here.

所谓喜欢 2024-11-15 15:49:23

我为你和任何其他想要这样做的人创建了一个设施。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文