You can also take a look at my LazyBusinessConversation class on my
blog post:
http://dotnetchris.wordpress.com/2009/12/18/implementing-nhibernate-long-conversation-with-no-httpmodules-or-aop-build-time-weaving/

I need to do a rewrite to the post for other changes I've made to that
but the LBC is basically the same. If you use a wrapper class you can
defer activation of the session until immediately as you need it. The
opening/closing session on every page request of lots of
implementations of NH usage always irritated me also. Even if it's a
light weight operation, it feels dirty to instantiate a NH session on
a page that doesn't even access the db!

On Jan 6, 5:26 pm, William Chang <[email protected]> wrote:
> I'm doing a little bit of NHibernate usage tweaking in my ASPNET MVC
> and I noticed every time I goto a server page it's opening a
> connection/session. The issue is I want to tell NHibernate to open a
> connection/session on demand (where there are queries) in my
> implemented System.Web.IHttpModule class (using BeginRequest and
> EndRequest)? How?
>
> My code snippet:
> private static void OnBeginRequest(Object sender, EventArgs e) {
>         NHibernate.ISession ormSession = GetSessionFactory
> ().OpenSession();
>         NHibernate.Context.CurrentSessionContext.Bind(ormSession);
>
> }
>
> Thank you for your help,
> William Changhttp://www.williamchang.org
-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.


Reply via email to