Unfortunately there are _many_ samples on the Internet that show almost the same initialization using the global.asax This use of an HttpModule for this purpose needs to be described as a best practice for initializing a session in NHibernate.
John Davidson Sent from my iPad On 2010-06-26, at 11:55, nadav s <[email protected]> wrote: > it has nothing to do with you're question, but i don't think its wise putting > this code in the global asax, and therefor making you're presentation layer > too much aware of you're persistancy. > you can write an HttpModule that does just that and register it in the web > config. > > On Sat, Jun 26, 2010 at 6:18 PM, Felipe Oriani <[email protected]> wrote: > Hi all, I'm developing an application using Asp.Net MVC. I've developed a > session per Request... so when the browser request something from server, the > app start an session. > > By the way, I have a page in my website that each second does a asynchronous > request by Json to take some information at cache (and the first time, the > cache is loaded from database, by repositories using Nhibernate). Everything > is fine, but when I see the application running with NHProf, I see all > "ISession" per request ... but any command is executed (because I load a > cache). > > I wonder, if doing so may cause a problem in the future? Or, with many > accesses the web application may become slow ? > > At my global.asax I do this: > > public override void Init() > { > base.Init(); > > PreRequestHandlerExecute += OpenNHibernateSession; > PostRequestHandlerExecute += DisposeNHibernateSession; > } > > private static void OpenNHibernateSession(object sender, EventArgs e) > { > if (RequestHelper.IsStaticFiles()) // || RequestHelper.IsJson()) > = to avoid calls Json if necessary, but i'll need use h in some called jsons > return; > > ManagedWebSessionContext.Bind(HttpContext.Current, > _sessionFactory.OpenSession()); > } > > private static void DisposeNHibernateSession(object sender, EventArgs > e) > { > if (RequestHelper.IsStaticFiles()) // || RequestHelper.IsJson()) > return; > > var session = > ManagedWebSessionContext.Unbind(HttpContext.Current, _sessionFactory); > if (session != null) > session.Dispose(); > > } > > If someone can help-me... I'll! appreciate > > PS: Sorry for my english! > > Cheers > > > > > -- > ______________________________________ > Felipe B. Oriani > [email protected] | www.felipeoriani.com.br > > "...Trabalhe quanto puder, tornando-se útil quanto possível..." , por André > Luiz > -- > 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. > > -- > 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. -- 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.
