title: asp.net mvc service layer and unit of work
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2238428/how-to-implement-unit-of-work-in-mvc-responsibility">How to implement Unit of work in MVC: Responsibility</a>  </p>
  </blockquote>
  
  
  
  <p>Hi. I am developing an ASP.NET MVC web application using the following architecture:
  UI -> Controller -> Service Layer -> Repository. The question here is where to expose the Unit Of Work pattern. For instance I have:</p>
  
  <pre><code>public class SomeController
  {
      public ActionResult AnAction()
      {
          using(var unitOfWork = UnitOfWorkManager.Create())
          {
              try
              {
                  this.ServiceA.Foo();
                  this.ServiceB.Foo();
  
                  unitOfWork.Commit();
              }
              catch(Exception ex)
              {
                  unitOfWork.Rollback();
              }         
          }
      }
  }
  </code></pre>
  
  <p>Is it ok for the controller to know about unit of work? What if we have several calls to different services but within the same action method and we need transactional behavior?</p>