my application is composed of several modules: a web site, and a few services that receive requests from client apps.
since all these modules manipulate pretty much the same data, I would like to have the same cache for all of them.
I'm using a static class to reference nHibernate's 2nd level cache (the SessionFactory object), and I've set up the web site and the web services within the same website on IIS.
however, the static SessionFactory variables are different between the web site and web service.
Here is the code for the static SessionManager class:
public static class SessionManager
{
private static ISessionFactory _sessionFactory = null;
private static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
if (System.Web.HttpContext.Current != null)
{
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger("General");
log.InfoFormat("creating a new session factory for process: {0} (id = {1}), \n stack trace is: {2}",
System.Diagnostics.Process.GetCurrentProcess().ProcessName, System.Diagnostics.Process.GetCurrentProcess().Id,
new System.Diagnostics.StackTrace().ToString());
_sessionFactory = DAOBase.GetSessionFactory();
}
else
{
_sessionFactory = DAOBase.GetSessionFactoryForWin();
}
}
return _sessionFactory;
}
}
public static void BindSessionToRequest()
{
ISession session = SessionManager.SessionFactory.OpenSession();
NHibernate.Context.CurrentSessionContext.Bind(session);
}
public static void UnbindSession()
{
ISession session = NHibernate.Context.CurrentSessionContext.Unbind(SessionManager.SessionFactory);
if (session != null && session.IsOpen)
{
session.Close();
}
}
public static ISession GetCurrentSession()
{
return SessionFactory.GetCurrentSession();
}
}
and the resulting logs:
for the web site:
2011-01-05 10:54:54 INFO General - creating a new session factory for process: aspnet_wp (id = 7892),
stack trace is: at Managers.SessionManager.get_SessionFactory()
at Managers.SessionManager.BindSessionToRequest()
at Managers.SessionPerRequestHttpModule.Context_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at System.Web.Hosting.ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
and for the web service:
10:55:20 INFO General - creating a new session factory for process: aspnet_wp (id = 7892),
stack trace is: at Managers.SessionManager.get_SessionFactory()
at Managers.SessionManager.BindSessionToRequest()
at Managers.SessionPerRequestHttpModule.Context_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at System.Web.Hosting.ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)
I'm using IIS5 (yuck, I know), and i've tried about every configuration option I could think of. I've created the site and service as virtual directories under the same site, i've set their protection level to 'Low (IIS process)' etc., but to no avail.
anyone got an idea?
thanks in advance,
Jhonny