title: Session and Transaction managment in Service Layer
body: <p>I have an application that will have some presentations layer (web, mobile, wpf, wcf, windows service to work on background etc...) and We are using NHibernate to persist the domain objects. We will have repositories (class library) to persist data, a service layer to use theses repositories to persist according to business rules. My question is, we do not know how to implement the a trasactional management in this service layer. We will probably use (more than one) repositories in a same service layer method and we need to control the transaction on the service layer. I would like to implement something like this (by attributes):</p>
  
  <pre><code>public class DomainObjectService
  {
     [Transactional]
     public bool CreateDomainObject(DomainObject domainObject, /* other parameters */)
     { 
         foreach(var item in /* collection */)
         {
             _itemRepository.Save(item);
         }
  
         if (/* some condition */) {
            /* change the domainObject here */
         }
  
         _domainObjectRepository.Save(domainObject);
     } 
  }
  </code></pre>
  
  <p>And does this Transactional attribute control my transactional with Commit/RollBack when we got erros. Is it possible? Or is there another solution to do this?</p>
  
  <p>Thank you</p>