【发布时间】:2017-10-08 17:29:48
【问题描述】:
我在一个 winForm 应用程序的中间,我正在使用 MVP 作为架构 和 NHIBERNATE 作为 ORM
到目前为止,一切都很好,但现在我想使用会话容器为我的 nh 会话存储和检索它们。 在 webform 中我使用 http 请求来存储主题没问题,但在 Winform 中我很困惑。 webform 的成本是 .
public class HttpSessionContainer : ISessionStorageContainer
{
private string _sessionKey = "NhibernateSession";
public ISession GetCurrentSession()
{
ISession nhSession = null;
if (HttpContext.Current.Items.Contains(_sessionKey))
nhSession = (ISession)HttpContext.Current.Items[_sessionKey];
return nhSession;
}
public void Store(ISession session)
{
if (HttpContext.Current.Items.Contains(_sessionKey))
HttpContext.Current.Items[_sessionKey] = session;
else
HttpContext.Current.Items.Add(_sessionKey, session);
}
}
如何转换该代码,以便我可以按 Form 存储我的会话。 谢谢
【问题讨论】:
-
我建议搜索有关“会话每会话”模式的信息。恕我直言,这将是在使用 MVP 模式的 Windows 窗体应用程序中管理 NHibernate 会话的理想方式。
标签: c# winforms session nhibernate mvp