Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Open Source
>
Web Development
>
Web Framework
&&
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
9.9K
Star
14.5K
Fork
4.2K
GVP
dotNET China
/
Furion
Code
Issues
0
Pull Requests
0
Insights
Pipelines
Service
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
UnitOfWork、Scope以及异常消息返回
Done
#I37WTV
秦秋随
Opened this issue
2021-02-10 21:07
### Furion 1.13 ----------- ### Web 项目类型 - [x] WebApi - [ ] Mvc - [ ] Razor Pages - [ ] Blazor Server ----------- ### 描述你的问题 Queer源码中有类AuthorizeFilterAttribute,其中有SaveLogAPI方法。当业务控制器调用BLL添加数据时,故意制造数据库异常,如非空等,存在以下问题: Queer作者标注:此处只能使用瞬态的数据库服务,因为业务中的数据库服务发生异常,这里会携带异常,无法继续写入数据库 使用了下述代码,但实际中,在一个scope中获取的数据上下文是相同的,异常继续 携带 ``` var logApiDB = App.ServiceProvider.GetService<IRepository<LogApiEntity>>(); await logApiDB.InsertNowAsync(logApiEntity); ``` 修改为下述代码,切换了上下文想规避携带异常,但是因为标记为UnitOfWork,新scope的操作也被添加到pool中并由UnitOfWorkFilter再次SavePoolNow(即使异常后没有再次请求保存)并再次引发异常,导致前端 获取到的提示信息不是控制器返回的异常提示 ``` var services = App.ServiceProvider.CreateScope().ServiceProvider; var logApiDB = services.GetService<IRepository<LogApiEntity>>(); await logApiDB.InsertNowAsync(logApiEntity); ``` 控制器的代码如下,实际得到的并不是输出 的异常,而是SavePoolNow产生的数据异常: ``` [ApiDescriptionSettings(KeepName = true, KeepVerb = true)] [HttpPost("PostNew")] [NonUnify] public virtual IActionResult Post(string values) { try{ //BLL中会尝试添加一个不符合数据库规则的数据 var result = getEntityBLL().Add(bank); } catch (Exception ex) { //处理异常并尝试向前端返回提示 string msg ="这是真正的异常"; // return new BadRequestObjectResult(msg); //不能拦截异常,必须以抛出异常的方式来结束事务 throw new Exception(msg); } } ``` ----------- ### 数据库信息 - [ ] Sqlite - [x] SqlServer - [ ] Mysql - [ ] Oracle - [ ] PGSql - [ ] Firebird - [ ] Cosmos ----------- ### 期待结果 可控的SavePoolNow以及如何妥善的处理InsertNowAsync等异常时回滚 -----------
### Furion 1.13 ----------- ### Web 项目类型 - [x] WebApi - [ ] Mvc - [ ] Razor Pages - [ ] Blazor Server ----------- ### 描述你的问题 Queer源码中有类AuthorizeFilterAttribute,其中有SaveLogAPI方法。当业务控制器调用BLL添加数据时,故意制造数据库异常,如非空等,存在以下问题: Queer作者标注:此处只能使用瞬态的数据库服务,因为业务中的数据库服务发生异常,这里会携带异常,无法继续写入数据库 使用了下述代码,但实际中,在一个scope中获取的数据上下文是相同的,异常继续 携带 ``` var logApiDB = App.ServiceProvider.GetService<IRepository<LogApiEntity>>(); await logApiDB.InsertNowAsync(logApiEntity); ``` 修改为下述代码,切换了上下文想规避携带异常,但是因为标记为UnitOfWork,新scope的操作也被添加到pool中并由UnitOfWorkFilter再次SavePoolNow(即使异常后没有再次请求保存)并再次引发异常,导致前端 获取到的提示信息不是控制器返回的异常提示 ``` var services = App.ServiceProvider.CreateScope().ServiceProvider; var logApiDB = services.GetService<IRepository<LogApiEntity>>(); await logApiDB.InsertNowAsync(logApiEntity); ``` 控制器的代码如下,实际得到的并不是输出 的异常,而是SavePoolNow产生的数据异常: ``` [ApiDescriptionSettings(KeepName = true, KeepVerb = true)] [HttpPost("PostNew")] [NonUnify] public virtual IActionResult Post(string values) { try{ //BLL中会尝试添加一个不符合数据库规则的数据 var result = getEntityBLL().Add(bank); } catch (Exception ex) { //处理异常并尝试向前端返回提示 string msg ="这是真正的异常"; // return new BadRequestObjectResult(msg); //不能拦截异常,必须以抛出异常的方式来结束事务 throw new Exception(msg); } } ``` ----------- ### 数据库信息 - [ ] Sqlite - [x] SqlServer - [ ] Mysql - [ ] Oracle - [ ] PGSql - [ ] Firebird - [ ] Cosmos ----------- ### 期待结果 可控的SavePoolNow以及如何妥善的处理InsertNowAsync等异常时回滚 -----------
Comments (
2
)
Sign in
to comment
Status
Done
Backlog
Doing
Done
Closed
Assignees
Not set
百小僧
monksoul
Assignee
Collaborator
+Assign
+Mention
dotNET China
chinadotnet
Assignee
Collaborator
+Assign
+Mention
Labels
建议
漏洞
重大调整
Not set
Label settings
Milestones
Furion 2021
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
参与者(3)
C#
1
https://gitee.com/dotnetchina/Furion.git
git@gitee.com:dotnetchina/Furion.git
dotnetchina
Furion
Furion
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register