在 ASP.NET MVC 中实现工作单元的方法

发布于 2024-09-24 07:41:55 字数 391 浏览 10 评论 0原文

我目前正在研究如何将 工作单元模式 添加到我现有的 ASP.NET MVC 应用程序中使用NHibernate。我看到各种实现有很多不同,并且我很难确定哪种方法在给定情况下最有效。

为了提供帮助,我想我应该要求 Stack Overflow 社区列出他们最喜欢的在 ASP.NET MVC 应用程序中实现工作单元模式的方法。

也许您在创建控制器时使用 IoC 实例化 NHibernate 会话,然后将其传递到存储库。或者您可能创建一个工作单元类/接口。描述您的方法后,请随时链接到其他资源。

另外,如果存在的话,请务必列出与您的方法相关的任何优点和缺点。

I'm currently researching how to add the Unit of Work pattern to my existing ASP.NET MVC application that uses NHibernate. I'm seeing a lot of variety in the various implementations and I'm having trouble determining which methods will work best in a given situation.

To help, I thought I would ask the Stack Overflow community to list their favorite ways of implementing the Unit of Work pattern in their ASP.NET MVC applications.

Maybe you use IoC to instantiate an NHibernate session when you create your controller and then pass that on to the repository. Or maybe you create a unit of work class/interface. Don't hesitate to link to additional resources after you describe your approach.

Also, be sure to list any pros and cons associated with your method should they exist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

つ可否回来 2024-10-01 07:41:55

我围绕 Entity Framework 4 POCO 对象实现了一个存储库/UoW 模式,结果对我们来说非常好。我们只将 UoW 暴露给业务/服务层,并让控制器(在我们的例子中是演示器)来调用这些服务来执行或检索数据。

我们实现的模式使用以下文章作为指南:http://msdn。 microsoft.com/en-us/library/ff714955.aspx

I implemented a Repository / UoW pattern around Entity Framework 4 POCO objects and it has turned out very well for us. We only expose the UoW to the Business/Service layer and have the Controller, or the Presenter in our case, to call these services to execute or retrieve data.

The pattern that we implemented used the following article as a guide: http://msdn.microsoft.com/en-us/library/ff714955.aspx

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