Just wondering, in an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?
Ive saw two example:
- One where the unit of work and repository both have an instance to the service layer..
Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable
Doesn’t use a service layer but its obvious that one could be use in that case.
- Second where the unit of work have an instance to the repository which have an instance to the service layer..
Link: http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit- of-work-patterns-with-entity-framework-4-0.aspx
What would be better ?
Thanks.
I’m not sure what you mean by “point to”, but I think transactions are the responsibility of the service layer, not persistence.
A persistence object can’t know if it’s part of a larger unit of work. The responsible service has references to all the model and persistence objects that make up the unit of work. The service is responsible for managing connections from the pool on behalf of the persistence objects as well. Obtain the connection, open the transaction, perform the work, either commit or rollback the transaction, and close the connection. That’s the service’s job.