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

  • Home
  • SEARCH
  • 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 87013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:20:11+00:00 2026-05-10T22:20:11+00:00

I am currently playing around with the HybridSessionBuilder class found on Jeffrey Palermo’s blog

  • 0

I am currently playing around with the HybridSessionBuilder class found on Jeffrey Palermo’s blog post:

http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/

Using this class, my repository looks like this:

public class UserRepository : IUserRepository {     private readonly ISessionBuilder _sessionBuilder;      public UserRepository(ISessionBuilder sessionBuilder)     {         _sessionBuilder = sessionBuilder;     }      public User GetByID(string userID)     {         using (ISession session = _sessionBuilder.GetSession())         {             return session.Get<User>(userID);         }     } } 

Is this the best way to go about managing the NHibernate session / factory? I’ve heard things about Unit of Work and creating a session per web request and flushing it at the end. From what I can tell, my current implementation isn’t doing any of this. It is basically relying on the Repository to grab the session from the session factory and use it to run the queries.

Are there any pitfalls to doing database access this way?

  • 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. 2026-05-10T22:20:11+00:00Added an answer on May 10, 2026 at 10:20 pm

    You should not wrap your ISession in a using statement — the point of passing the ISessionBuilder into the repository constructor (dependency injection) is that the calling code is responsible for controlling the life cycle of the ISession. By wrapping it in a using, Dispose() is called on the ISession and you won’t be able to lazy load object members or persist it.

    We do something similar by just passing in an ISession to the repository constructor. Mr. Palermo’s code, as I understand it, simply adds lazy initialization of the ISession. I don’t think that’s needed because why would you new up a repository if you’re not going to use it?

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

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Having multiple languages in one project is actually quite common,… May 11, 2026 at 10:08 am
  • added an answer Check out Function#Apply(). It lets you pass the parameters as… May 11, 2026 at 10:08 am
  • added an answer You can check your classpath. It should include atleast The… May 11, 2026 at 10:08 am

Related Questions

I am currently playing around with the HybridSessionBuilder class found on Jeffrey Palermo's blog
I am currently playing around with the Asp.Net mvc framework and loving it compared
Hallo i am currently playing around with castle projects ActiveRecord and the remoting facility.
I am currently aware that ASP.NET 2.0 is out and about and that there
I am currently working on a project and my goal is to locate text
I am currently using Windows Server 2008 Standard and have several Hyper V machines.
I am currently using the following command to upload my site content: scp -r
I am currently working on a project with specific requirements. A brief overview of
I am currently building in Version 3.5 of the .Net framework and I have
I am currently in the process of creating my own blog and I have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.