Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:35:15+00:00 2026-05-25T13:35:15+00:00

This is based on: http://nhforge.org/blogs/nhibernate/archive/2011/03/03/effective-nhibernate-session-management-for-web-apps.aspx Code is here: https://gist.github.com/852307 My questions are, in the

  • 0

This is based on: http://nhforge.org/blogs/nhibernate/archive/2011/03/03/effective-nhibernate-session-management-for-web-apps.aspx

Code is here: https://gist.github.com/852307

My questions are, in the DAO:

//Example of dao
public class Dao<T> : IDao<T>
{
    private readonly ISessionFactory sessionFactory;

    public Dao(ISessionFactory sessionFactory)
    {
        this.sessionFactory = sessionFactory;
    }

    public void Save(T transient)
    {
        sessionFactory.GetCurrentSession().Save(transient);
    }
}

I guess the ISessionFactory get’s autoatically wired up using windsor correct?

public class NHibernateInstaller : IWindsorInstaller
{
    #region IWindsorInstaller Members

    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.Register(Component.For<ISessionFactory>()
                               .UsingFactoryMethod(k => BuildSessionFactory()));

        container.Register(Component.For<NHibernateSessionModule>());

        container.Register(Component.For<ISessionFactoryProvider>().AsFactory());

        container.Register(Component.For<IEnumerable<ISessionFactory>>()
                                    .UsingFactoryMethod(k => k.ResolveAll<ISessionFactory>()));

        HttpContext.Current.Application[SessionFactoryProvider.Key]
                        = container.Resolve<ISessionFactoryProvider>();
    }

    #endregion
    public ISessionFactory BuildSessionFactory() { ... }
}

But in the DAO, when the method is called:

sessionFactory.GetCurrentSession()

How does this snippet and the HttpModule that opens the session work?

I don’t see how GetCurrentSession() hooks into the session that was opened by the HttpModule since GetCurrentSession is a built in method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:35:16+00:00Added an answer on May 25, 2026 at 1:35 pm

    It’s using NHibernate contextual sessions:
    http://www.nhforge.org/doc/nh/en/index.html#architecture-current-session

    All the magic happens in LazySessionContext. Whenever the bind method is called this saves the session in an nhibernate context. In your case the context would be LazySessionContext which is a custom context (inherits from NH’s ICurrentSessionContext) used by this application. There are 4 or 5 different types of standard contextual sessions in version 3.2 of nhibernate.

    The GetCurrentSession method basically retrieves your saved (saved session in bind call) NH session from earlier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an ogre3d tutorial based on this setup http://www.ogre3d.org/wiki/index.php/SettingUpAnApplication#XCode I've followed all steps
Seeing this: http://www.suckless.org/wiki.html . A wiki based on Mercurial. Are there any other non-code
I'm going to do a wpf application using MVVM(It based on http://www.codeproject.com/KB/WPF/MVVMQuickTutorial.aspx ). This
Based on this: http://man7.org/tlpi/code/online/book/procexec/multi_wait.c.html int main(int argc, char *argv[]) { int numDead; /* Number
I've just been researching the ActiveRecord pattern, and based on this ( http://en.wikipedia.org/wiki/Active_record_pattern ),
I have been writting a keyword search script based on this tutorial: http://www.hackosis.com/2007/11/06/howto-simple-search-engine-with-php-and-mysql/ Like
This is the URL. http://www.tumblr.com/ I think that its based on prototype, and is
Some time ago I created this LAMP based web. At the time I wrote
Based on http://ant.apache.org/manual/Types/mapper.html Here's my target: <target name=ms.copy-example> <copy todir=${ms.custom}> <fileset dir=${ms.example}> <include name=build.xml
I'm using a Grails plugin for ajax upload, http://grails.org/plugin/ajax-uploader , that is directly based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.