Merged
Conversation
Owner
|
增加 IUnitOfWork.Disable() 禁用事务开启的方法,以及单元测试 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
调用此方法后,工作单元将失效,即不会开启事务,即便仓储赋值了 Repo.UnitOfWork=uow 也不会开启事务。
添加此方法不会影响以前代码的正常使用。
在已有 Insert/Update/Delete 以后调用此方法将会抛出异常,因为这时已经开启事务,不能使工作单元生效。
应用场景:类似于ABP的在应用逻辑层的自动工作单元(自动开启事务),利用AOP在执行方法以前开启工作单元,执行完毕以后自动提交,但是此功能可以设置Attribute来进行关闭。本方法就是能是AOP在执行方法前通过检测Attribute来进行关闭工作单元。因为目前需要给每个仓储赋值工作单元过于麻烦,所以在依赖注入仓储时,可以封装默认就注入工作单元,类似于
这样实际上在使用仓储的时候就赋值了工作单元,可以理解为默认开启了工作单元,但是我们肯定有不需要开启工作单元的情况,所以设置一个关闭的方法。
单元测试已通过: