Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top