CallSessionContext,ThreadLocalSessionContext和ThreadStaticSessionContext之间的区别 [英] Difference between CallSessionContext, ThreadLocalSessionContext and ThreadStaticSessionContext

查看:56
本文介绍了CallSessionContext,ThreadLocalSessionContext和ThreadStaticSessionContext之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自 NHibernate文档,说明不多.

这三个之间有什么区别?

What is the difference between those three ?

在哪种情况下,其中一种情况比其他情况更可取?

In what situation that one of those context is more preferable than the others ?

P.S. ThreadLocalSessionContext在文档中不存在,但在 NHibernate dll中确实存在.

P.S. ThreadLocalSessionContext doesn't exist in the documentation, but it does exist in NHibernate dll.

推荐答案

当前似乎无法使用 ThreadLocalSessionContext .没有支持它的配置,只有单元测试在NHibernate中引用它.

It doesn't look like ThreadLocalSessionContext can currently be used. There is no configuration that supports it's use and it's only referenced within NHibernate by a unit test.

根据代码 CallSessionContext 是一种在.Net远程处理中处理会话的方法,有关更多详细信息,请参见下面的代码中的注释.看起来NHibernate基本将会话存储在远程调用上下文中.可以在此处找到有关远程调用上下文的更多信息.

According to the code CallSessionContext is a way of handling sessions in .Net remoting see comments in code below for more detail. It looks like NHibernate basically stores the session in the remoting call context. More info about remoting call contexts can be found here

/// <summary>
/// Provides a <see cref="ISessionFactory.GetCurrentSession()">current session</see>
/// for each <see cref="System.Runtime.Remoting.Messaging.CallContext"/>.
/// Not recommended for .NET 2.0 web applications.

ThreadStaticSessionContext 用于处理多线程应用程序中的会话.它使用[ThreadStatic]属性声明会话,以便每个线程都有一个会话.我目前正在使用.请参阅此SO链接以获取有关如何使用它的代码示例:

ThreadStaticSessionContext is used for handling sessions in multi-threaded applications. It uses a [ThreadStatic] attribute to declare the session such that there is a session per thread. I currently use this. See this SO link for a code example of how you would use it: What is the best NHibernate session management approach for using in a multithread windows service application?

除此之外,NHibernate似乎还在3.2版中添加了另一个名为 WcfOperationSessionContext 的会话上下文.下面是对代码的描述:

Also in addition to this it looks like NHibernate is adding another session context in version 3.2 called WcfOperationSessionContext. Below is the description from the code:

/// <summary>
/// Provides a <see cref="ISessionFactory.GetCurrentSession()">current session</see>
/// for the current OperationContext in WCF. Works only during the lifetime of a WCF operation.
/// </summary>

要回答第二个问题,这实际上取决于您要实现的应用程序类型以及会话的使用方式.希望在nhibernate文档和上面的描述之间,您将对应该使用的上下文有更好的了解.

To answer your 2nd question it really depends on what type of application you are implementing and how you are using your sessions. Hopefully between the nhibernate documentation and the descriptions above you'll have a better idea of what context you should use.

这篇关于CallSessionContext,ThreadLocalSessionContext和ThreadStaticSessionContext之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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