Possible Duplicate:
How to implement Unit of work in MVC: Responsibility
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:
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();
}
}
}
}
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?