Hello!
I have an Asp.Net WebForms application, with nhibernate 3.3, and i'm trying
to do an efective session per request control, using best practices and so
on.
Untill yesterday i was building my session factory upon the
Application_Start event, in global.asax, and controlling the session in the
Begin_request and End_Request events, like this:
public void Application_BeginRequest(object sender, EventArgs e)
{
ISession currentSession;
if
(System.Web.HttpContext.Current.Items.Contains("NHCurrentSession"))
{
currentSession =
(ISession)System.Web.HttpContext.Current.Items["NHCurrentSession"];
if (currentSession.Transaction.IsActive)
{
currentSession.Transaction.Rollback();
currentSession.Transaction.Dispose();
}
currentSession.Dispose();
System.Web.HttpContext.Current.Items.Remove("NHCurrentSession");
}
}
public void Application_EndRequest(object sender, EventArgs e)
{
ISession currentSession;
if
(System.Web.HttpContext.Current.Items.Contains("NHCurrentSession"))
{
currentSession =
(ISession)System.Web.HttpContext.Current.Items["NHCurrentSession"];
if(currentSession.Transaction.IsActive)
{
currentSession.Transaction.Commit();
currentSession.Transaction.Dispose();
}
currentSession.Dispose();
System.Web.HttpContext.Current.Items.Remove("NHCurrentSession");
}
}
I'd like to know a better way to do this, and how to configure this in the
web.config / hibernate
I tried something different, using CurrentSessionContext, but it works only
when I use the configuration <property
name="current_session_context_class">thread_static</property>. When i try
<property name="current_session_context_class">managed_web</property> it
fails.
Can I use thread_static in the web?
I heard about unhaddins, but I couldn't find an easy to follow example
using webforms, only wcf, and i was wondering if anhaddins is compatible
with nh 3.3.
My second option is building a webmodule, but i don't know how to.
My final goal is to use in a windows form application the same architeture
i'm using in the web.
[]s
*Vitor Luiz Rubio* \( ^^ ' )/
Arquiteto de Software|Analista de Sistemas Sr.|Programador
[email protected]
[email protected]
[email protected]
Cel. +55 (11) 97992-4544
Contatos <http://www.meadiciona.com/vitorrubio> |
Blog<http://vitorrubio.blogspot.com/>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.