为什么要使用工作模式的单元上的NHibernate的会议的顶部? [英] Why would I use the Unit of Work pattern on top of an NHibernate session?

查看:144
本文介绍了为什么要使用工作模式的单元上的NHibernate的会议的顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我会写上什么是NHibernate的已经提供的顶部UOW执行?任何真实世界的例子?

When would I write a UoW implementation on top of what is already provided by NHibernate? Any real world examples?

推荐答案

工作已经由NHibernate的规定,所以没有理由做这样你所描述的单位工作单元。

The Unit Of Work you are describing is already provided by NHibernate so there is no reason to do such a unit of work.

我们已经在我们的WCF服务是什么工作,它包含在我们的当前工作单元应用的重要信息更高层次的单位。这包括抽象的NHibernate的ISession我们。当你打破它,你有适合分为三类

What we have in our WCF Service is a higher level unit of work that contains information important in our application for the current unit of work. This includes abstracting the NHibernate ISession for us. When you break it down you have code that fits into three categories


  1. 这需要处理一个工作单元代码的代码。不要紧,谁备份工作单元。这可能是NHibernate的,iBatis的或自定义的ORM。所有的代码需要做的是负载,回滚,保存,等它不会也不应该在乎用来做这样的机制。

  1. Code that needs to deal with a Unit Of Work. It doesn't matter who backs the unit of work. It could be NHibernate, iBatis or a custom ORM. All the code needs to do is Load, Rollback, Save, etc. It doesn't nor should it care about the mechanism used to do so.

代码需要处理一个ISession直接,因为它做NHibernate的具体事情。通常,这与需要创建复杂的查询做的。

Code that needs to deal with an ISession directly because it's doing NHibernate specific things. Usually this has to do with complex queries that need to be created.

不需要知道它是在一个单位工作运行或访问的Isession 。我们完全可以忽略这个,因为这讨论的一部分。

Doesn't need to know that it's running in a Unit Of Work or access the ISession. We can completely ignore this as part of this discussion.

而在1码可以只对工作的一个ISession我们偏好是试图抽象掉的东西,我们不直接控制,或有可能改变的代码。这具有用于两个原因值。

While code in 1. could just work against an ISession our preference is to try to abstract away things in the code that we do not directly control or that could change. This has value for two reasons.


  • 当我们开始我们不是100%NHibernate的销售。我们正在考虑iBatis的什么的习惯。显然,这已经不再是一个问题。

  • When we started we weren't 100% sold on NHibernate. We were considering iBatis or something custom. Obviously this is no longer an issue.

整个团队不是NHibernate的专家我们也不希望他们。对于大部分人写的融入1.类别代码和所有他们知道的是我们组的工作。当2类代码必须获得书面它就会被人们上了解NHibernate的好团队编写。

The entire team are not experts in NHibernate nor do we want them to be. For the most part people write code that fits into category 1. and all they know about is our Unit Of Work. When code in category 2. has to get written it gets written by the people on the team that understand NHibernate well.

所以要收我会说,单位你所谈论的是不是需要我会建议工作的类型这项工作的一个更高层次的单位可以提供大量有价值的。

So to close I would say that the type of Unit Of Work you are talking about is not needed I would suggest that a higher level Unit of Work can provide a lot of value.

这篇关于为什么要使用工作模式的单元上的NHibernate的会议的顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆