将 SharpArch Nhibernate 与不同类型的 SessionStorage 结合使用

发布于 2024-12-03 02:26:07 字数 1265 浏览 2 评论 0原文

我有一个服务器应用程序,其中有 3 种场景,其中我似乎需要不同类型的 nhibernate 会话:

  1. 直接从服务器本身调用存储库(引导时)
  2. 从 Ria 服务调用存储库(默认 ASP.NET Memberschip服务)
  3. 从 WCF 服务调用存储库

目前我已经使用 Sharparch 设置了我的 nhibernate 配置,如下所示

/// <summary>
/// Due to issues on IIS7, the NHibernate initialization cannot reside in Init() but
/// must only be called once.  Consequently, we invoke a thread-safe singleton class to 
/// ensure it's only initialized once.
/// </summary>
protected void Application_BeginRequest(object sender, EventArgs e)
{
   NHibernateInitializer.Instance().InitializeNHibernateOnce(
       () => InitializeNHibernateSession());
    BootStrapOnce();
}       

private void InitializeNHibernateSession()
{
    NHibernateSession.Init(
        wcfSessionStorage,
        new string[] { Server.MapPath("~/bin/bla.Interfaces.dll") },
        Server.MapPath("~/Web.config"));
}

这适用于第三种情况,但不适用于前两种情况。 它似乎需要一些 wcf 会话特定的上下文。

SharpArch Init 方法似乎可以防止使用另一种类型的会话存储重新初始化它;

为三种不同类型的上下文创建不同会话的最佳方法是什么?

对我来说,这篇文章似乎与这个相关 这帮助我寻找正确的方向,但到目前为止我还没有找到解决方案。

I have a server application where I have 3 scenarios in which I seem to need different kind of nhibernate sessions:

  1. Calls to the repository directly from the server itself (while bootstrapping)
  2. Calls to the repository coming from a Ria Service (default ASP.NET Memberschip Service)
  3. Calls to the repository coming from a WCF Service

Currently I have set up my nhibernate config with sharparch like this

/// <summary>
/// Due to issues on IIS7, the NHibernate initialization cannot reside in Init() but
/// must only be called once.  Consequently, we invoke a thread-safe singleton class to 
/// ensure it's only initialized once.
/// </summary>
protected void Application_BeginRequest(object sender, EventArgs e)
{
   NHibernateInitializer.Instance().InitializeNHibernateOnce(
       () => InitializeNHibernateSession());
    BootStrapOnce();
}       

private void InitializeNHibernateSession()
{
    NHibernateSession.Init(
        wcfSessionStorage,
        new string[] { Server.MapPath("~/bin/bla.Interfaces.dll") },
        Server.MapPath("~/Web.config"));
}

This works for the third scenario, but not for the first two.
It seems to need some wcf-session-specific context.

The SharpArch Init method seems to have protection from re-initializing it with another type of sessionstorage;

What is the best way to create a different session for three different kinds of contexts?

To me it looks like this post seems related to this one which has helped me looking in the right direction, but I have not found a solution so far.

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

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

发布评论

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

评论(1

蔚蓝源自深海 2024-12-10 02:26:07

我不确定您是否能够使用 S# 实现您想要的功能。原因是您确实希望拥有 3 个独立的 Nhibernate 会话,每个会话都有自己的存储机制。当前的实现仅允许一种存储机制,无论会话数量如何。

我可以轻松地为您找到 # 的 1 和 3,但不是两个,因为我从未使用过 RIA 服务。对于 1 和 3 的情况,您需要将 WCF 服务从站点中取出并将其放在自己的站点中。没有办法真正解决这个问题,因为它们的会话生命周期不同。

您的另一种选择是为 NHibernate 提供您自己的会话管理,而不是使用默认的 S# 会话管理。您可以查看 S# 版本的代码并基于该版本创建您自己的代码。

I'm not sure you are going to be able to do what you are wanting with S#. The reason being is that you are really wanting to have 3 separate Nhibernate sessions, each with it's own storage mechanism. The current implementation only allows for one storage mechanism, regardless of the number of sessions.

I can easily get you #'s 1 and 3, but not two since I've never used RIA services. In the case of 1 and 3, you would need to take the WCF service out of the site and have it in it's own site. No way of really getting around that as their session lifecycles are different.

Your other option would be to come up with your own Session Management for NHibernate and not use the default S# one. You could look at the code for the S# version and create your own based on that.

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