If you're initializing the NHib stuff in Application_BeginRequest, one additional optimization you can make is to only do so for non-static requests:
This is the approach used in the awesome Who Can Help Me sample MVC app: http://whocanhelpme.codeplex.com/SourceControl/changeset/view/53686#883589 protected void Application_BeginRequest(object sender, EventArgs e) { // Only initialise the NHibernate Sessions for a non static, i.e. Controller Action request if (!this.Request.IsStaticFile()) { NHibernateInitializer.Instance().Initialize (this.InitialiseNHibernateSessions); } } Though I don't think this is as efficient as the attribute per usage approach. On Jan 6, 5:28 pm, Jason Meckley <[email protected]> wrote: > opening a session doesn't mean you will open a database connection. > once you call begin transaction or a CRUD operation it will open the > connection if it doesn't exist. > > I used to mange my session and transactions all within an http module. > whether I needed an open connection or not. however i found that > managing the session scope at the module level and transactions with > an ActionFilter keeps the session-per-request scope while efficiently > using transactions. > > On Jan 6, 6:57 pm, José F. Romaniello <[email protected]> wrote: > > > Am I wrong if I say that this code should NOT open a connection? > > > NHibernate.ISession ormSession = GetSessionFactory().OpenSession(); > > > NHibernate.Context.CurrentSessionContext.Bind(ormSession);
-- 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.
