在业务层中实现事务是一个好的做法吗
我们正在考虑在 ASP.NET Web 应用程序中实现事务。它是一个三层架构。 我们从业务层调用Web 服务,并计划通过设置TransactionOPtion 属性在Web 服务中实现事务。
来到数据层,在数据层中实现事务是一个不错的选择还是应该从业务层调用它。 如果我从业务层启动事务,我相信我们需要将事务上下文传递到数据层,这对我来说没有意义,因为我可以在数据层本身中启动事务。我没有与不同的数据库交谈,也没有来自 BusinessLayer 的多个方法调用。所以我认为在这种情况下我们不需要在业务层进行事务。 您能验证/纠正我的理解吗?
谢谢
索尼
We are looking at implementing transactions in our ASP.NET web application. Its a three layered architecture.
We are calling Web Services from the Business Layer and are planning to implement transactions in the Web service by setting the TransactionOPtion attribute.
Coming to the datalayer, is it a good option to implement transactions in the data layer or should I call it from the Business Layer.
If I start the transaction from the Business Layer, I believe we will need to pass the transaction context to the Datalayer which according to me does not make sense since I can start the transaction in the Datalyer itself. I'm not talking to different Databases nor do I have multiple method calls from the BusinessLayer. So I dont think that we need to have transactions in the business layer in this context.
Could you please verify/correct my understanding?
Thanks
Soni
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从对业务层的一次调用中多次调用数据层,我不相信您可以避免将事务范围提升到业务层。
如果您将自己限制为每个业务层调用一个数据层调用,那么当然,您不需要业务层级别事务,并且可以将它们仅保留在数据层上。
If you have multiple calls to the data layer from one call to the business layer, I don't believe you can avoid elevating the transaction scope to the business layer.
If you restrict yourself to one data layer call per business layer call, then of course, you don't need business layer level transactions, and you can keep them only on your data layer.
它不会让跟踪交易变得容易。
打开和关闭交易的职责将转移到业务层。
->层与层之间的耦合度将远远超出您调用 Web 服务时的预期。
It won't make it easy to track transactions.
Responsibility for opening and closing the transactions will move to the business layer.
-> The coupling between the layers will be far more than you would expect when you call a webservice.