2011-07-11 22 views

回答

7

它看起來不像ThreadLocalSessionContext目前可以使用。沒有配置支持它的使用,它只在NHibernate中通過單元測試引用。

根據代碼CallSessionContext是一種處理.Net遠程處理會話的方式,請參閱下面代碼中的註釋以獲取更多詳細信息。看起來NHibernate基本上將會話存儲在遠程調用上下文中。關於遠程調用上下文更多信息,可以發現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鏈接,你將如何使用它的代碼示例:What is the best NHibernate session management approach for using in a multithread windows service application?

而且除了這個,它看起來像NHibernate的是增加在名爲WcfOperationSessionContext 3.2版本的另一個會話的上下文。下面是從代碼的說明:

/// <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文檔和上面的描述之間您可以更好地瞭解您應該使用的上下文。