Possible duplicate:
How to implement the Unit of work in MVC: Responsibility
Hey. I am developing an ASP.NET MVC web application using the following architecture: UI -> Controller -> Service Layer -> Repository. This raises the question of where the "Unit of Work" template can be exposed. For example, 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 good for the controller to know the amount of work? What if we have several calls for different services, but within the same method of action, and we need transactional behavior?
source
share