views:

159

answers:

3

Hi, I have a certain scenario where inserts and updates are done on multiple tables based on some constraints ..so its natural to use Transaction scope for these scenarios.Now,I have a respository layer and a service layer. service layer mediates the repository and the UI and is persistent ignorant. Now i m confused where to use the transactions either in service or in repository layers.I am not using any ORMs. I have also seen people advocating about Unit of work pattern for such scenarios. are there any examples about unit of work pattern that suits my current scenarios,all the examples i have seen are using ORMS.

Thanks,

A: 

Some questions that may help answer this.

Which layer understands the transactional requirements? What is the granularity of your repository interface?

In my world we tend to have fine-grained persistence operations, Insert, Update, Delete. and then compose them in the service layer. Hence in this environment it seems obvious to me that it's the service layer which understands the transactional scope.

djna
+1  A: 

This is going to depend on your system of course, but typically I would do it in the service layer. Especially if your service layer methods call multiple fine-grained repository methods and expect them to either all commit or all rollback.

Eric Petroelje
A: 

My repository class do CRUD operations without any rollback or commit..and each repositoy is mapped to a particular table. for ex: customer repository will implement icustomerRepository. and customerService calls iCustomerRepository. Can i get a good example on how to implement Unit of work pattern for my scenario

Thanks again,

Rakesh