在服务层或存储库层管理事务? [英] Managing Transactions either in service layer or repository layer?

查看:72
本文介绍了在服务层或存储库层管理事务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个特定的场景,根据一些约束在多个表上完成插入和更新......所以很自然地将事务范围用于这些场景.现在,我有一个存储库层和一个服务层.服务层调解存储库和 UI,并且是持久的无知.现在我很困惑在哪里使用服务或存储库层中的事务.我没有使用任何 ORM.我也看到有人在这种情况下提倡使用工作单元模式.有没有适合我当前场景的工作单元模式示例,我看到的所有示例都使用 ORMS.

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.

谢谢,

推荐答案

这当然取决于你的系统,但通常我会在服务层进行.特别是如果您的服务层方法调用多个细粒度存储库方法并期望它们全部提交或全部回滚.

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.

这篇关于在服务层或存储库层管理事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆