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 6557001
In Process

The Archive Base Latest Questions

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

I am looking into the UoW pattern and have 3 questions. public class UnitofWork

  • 0

I am looking into the UoW pattern and have 3 questions.

  public class UnitofWork : unitofwork.Models.IUnitofWork
    {
        private readonly ITransaction transaction;
        private readonly ISession session;

        public UnitofWork(ISession session)
        {
            this.session = session;
            session.FlushMode = FlushMode.Auto;
            transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);
        }

        public void Commit()
        {
            if (!transaction.IsActive)
            {
                throw new InvalidOperationException("Oops! We don't have an active transaction");
            }
            transaction.Commit();
        }

        public void Rollback()
        {
            if (transaction.IsActive)
            {
                transaction.Rollback();
            }
        }

        public void Dispose()
        {
            if (session.IsOpen)
            {
                session.Close();
            }
        }
    }
  1. I just learning about “IsolationLevels” and I am wondering which one should you be using? What happens if you need to make use of multiple “IsolationLevels” for different transactions? How would you configure your UoW(would you make multiple implementations of the above class?)

  2. Other then Rollback and Commit was usually goes into the UoW? I know stuff like creating,updating,getting queries would go into a repository(if your using this pattern) So what else would you typicall see in it?

  3. I copied this UoW from some site(don’t have it on hand right now) and made changes it to fit my needs(for instance I am using ninject so I felt there was no point in the UoW taking in the sessionFactory and opening a session in the UoW)

I am wondering what is the Dispose for? I seen this a few times before(some seem to implement IDispose).

I don’t actually use it right now in any of my code. I am wondering if it is necessary for me as I mentioned I am using ninject and that handles the session(ie closes it once I am done)

  public void Dispose()
        {
            if (session.IsOpen)
            {
                session.Close();
            }
        }

Edit

I added this to my unit of work

   public void BeginTransaction()
    {
        transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);
    }

    public void BeginTransaction(IsolationLevel level)
    {
        transaction = session.BeginTransaction(level);
    }

I removed it from the constructor

  • 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:01:09+00:00Added an answer on May 25, 2026 at 1:01 pm

    The ISession itself is a unit-of-work implementation, so implementing your own is entirely optional.

    1. IsolationLevel is declared in the System.Data namespace. ReadCommitted is the most commonly used; this is also the default for SQL Server. I tried using Chaos once just because I like the name but SQL Server doesn’t support it.
    2. The code you have in the question creates a transaction as soon as the session is opened, so it’s a transaction per UOW implementation; note that if you call Commit or Rollback, any additional operations will occur outside of transaction scope. I really dislike this and prefer to control my own transaction scope, so I would have a BeginTransaction in my UOW.
    3. Classes that implement IDisposable must implement the Dispose method and should be used in a using block or disposed of manually. It means that the class has clean up operations that need to run, such as closing the ISession. Here, the Dispose method should just call ISession.Dispose instead of just closing the session.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking into IKVMing Apache's FOP project to use with our .NET
I'm looking into using Visual Studio 2008's built in unit test projects instead of
I've recently been looking into targeting the .NET Client Profile for a WPF application
I'm looking into writing a audio syntesizer in Java, and was wondering if anybody
I'm looking into sending regular automated text-messages to a list of subscribed users. Having
I've been looking into different web statistics programs for my site, and one promising
I am looking into game programming in Java to see if it is feasible.
I've been looking into OSGi recently and think it looks like a really good
I'm looking into a mechanism for serialize data to be passed over a socket
I am looking into internationalizing a Flex application I am working on and I

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.