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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:32:58+00:00 2026-05-14T22:32:58+00:00

I’m in my first time with DDD, so I’m begginer! So, let’s take it’s

  • 0

I’m in my first time with DDD, so I’m begginer! So, let’s take it’s very simple 😀
I developed an application using asp.net mvc 2 , ddd and nhibernate. I have a domain model in a class library, my repositories in another class library, and an asp.net mvc 2 application. My Repository base class, I have a construct that I inject and dependency (my unique ISessionFactory object started in global.asax), the code is:

public class Repository<T> : IRepository<T>
    where T : Entidade
{
    protected ISessionFactory SessionFactory { get; private set; }
    protected ISession Session
    {
        get { return SessionFactory.GetCurrentSession(); }
    }

    protected Repository(ISessionFactory sessionFactory)
    {
        SessionFactory = sessionFactory;
    }        

    public void Save(T entity)
    {
        Session.SaveOrUpdate(entity);
    }

    public void Delete(T entity)
    {
        Session.Delete(entity);
    }

    public T Get(long key)
    {
        return Session.Get<T>(key);
    }

    public IList<T> FindAll()
    {
        return Session.CreateCriteria(typeof(T)).SetCacheable(true).List<T>();
    }
}

And After I have the spefic repositories, like this:

public class DocumentRepository : Repository<Domain.Document>, IDocumentRepository
{
        // constructor
        public DocumentRepository (ISessionFactory sessionFactory) : base(sessionFactory) 
        { }

        public IList<Domain.Document> GetByType(int idType)
        {
            var result = Session.CreateQuery("from Document d where d.Type.Id = :IdType")
                .SetParameter("IdType", idType)
                .List<Domain.Document>();

            return result;
        }
}

there is not control of transaction in this code, and it’s working fine, but, I would like to make something to control this repositories in my controller of asp.net mvc, something simple, like this:

using (var tx = /* what can I put here ? */) {
   try 
   {
     _repositoryA.Save(objA);
     _repositoryB.Save(objB);
     _repositotyC.Delete(objC);
     /* ... others tasks ... */

     tx.Commit();
   }
   catch
   {
     tx.RollBack();
   }
}

I’ve heared about NHibernateUnitOfWork, but i don’t know :(, How Can I configure NHibernateUnitOfWork to work with my repositories ? Should I change the my simple repository ? Sugestions are welcome!

So, thanks if somebody read to here! If can help me, I appretiate!

PS: Sorry for my english!

bye =D

  • 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-14T22:32:59+00:00Added an answer on May 14, 2026 at 10:32 pm

    There is an excellent library called NCommon (source) that provides a great UnitOfWork implementation built right in. Version 1.1 allows you to do something like:

    public class Foo
    {
        private readonly IRepository<Stuff> _repository;
    
        public Foo(IRepository<Stuff> repository)
        {
             _repository = repository;
        }
    
        public void DoSomething()
        {
            using (var scope = new UnitOfWorkScope())
            {
               _repository.Save(a);
               scope.Commit();
            }
        }
    }
    

    It integrates with the latest NHibernate and even uses NHibernate.Linq to provide some powerful querying features. You have little or nothing to build yourself and it works great out of the box.

    Edit:

    I elaborated on my example to show the full recommended way to use NCommon in a project with dependency-injection.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm looking for suggestions for debugging... If you view this site in Firefox or
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.