From 7f3f8e713b536c8a523146aff3af1d4c2f500816 Mon Sep 17 00:00:00 2001 From: wangjun Date: Tue, 8 Aug 2023 21:18:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7volo.abp=207.3.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aspnet-core/Directory.Build.Volo.targets | 178 ++++++------ aspnet-core/Directory.Build.targets | 60 ++-- aspnet-core/Lion.AbpPro.All.sln | 7 + .../Lion.AbpPro.Core/Lion.AbpPro.Core.csproj | 4 - .../Lion.AbpPro.EntityFrameworkCore.csproj | 1 + ...on.AbpPro.EntityFrameworkCore.Tests.csproj | 70 ++--- .../Services/BlogAppService.cs | 268 +++++++++--------- ...AbpPro.BasicManagement.HttpApi.Host.csproj | 1 - ....AbpPro.BasicManagement.Application.csproj | 6 +- ....AbpPro.FileManagement.HttpApi.Host.csproj | 2 +- ...NotificationManagement.HttpApi.Host.csproj | 1 - .../AbpProHttpApiHostModule.Configure.cs | 2 +- .../Hangfire/RecurringJobsExtensions.cs | 5 +- .../Lion.AbpPro.HttpApi.Host/GlobalUsings.cs | 1 + .../Lion.AbpPro.HttpApi.Host.csproj | 1 - .../host/Lion.AbpPro.HttpApi.Host/Startup.cs | 1 + .../Lion.AbpPro.FreeSqlRepository.csproj | 2 +- .../GlobalUsings.cs | 6 + .../Mvc/Filters/AbpProExceptionFilter.cs | 100 ++++--- .../aspnet-core/Directory.Build.Volo.targets | 176 ++++++------ .../aspnet-core/Directory.Build.targets | 61 ++-- .../Hangfire/RecurringJobsExtensions.cs | 9 +- .../MyProjectNameHttpApiHostModule.cs | 2 +- ...ame.MyProjectName.FreeSqlRepository.csproj | 2 +- .../Directory.Build.Volo.targets | 176 ++++++------ .../Directory.Build.targets | 60 ++-- .../aspnet-core/Directory.Build.Volo.targets | 176 ++++++------ .../aspnet-core/Directory.Build.targets | 61 ++-- .../Hangfire/RecurringJobsExtensions.cs | 9 +- .../MyProjectNameHttpApiHostModule.cs | 2 +- ...ame.MyProjectName.FreeSqlRepository.csproj | 2 +- 31 files changed, 741 insertions(+), 711 deletions(-) diff --git a/aspnet-core/Directory.Build.Volo.targets b/aspnet-core/Directory.Build.Volo.targets index 0ccb7e9f3..b8b6e199e 100644 --- a/aspnet-core/Directory.Build.Volo.targets +++ b/aspnet-core/Directory.Build.Volo.targets @@ -1,93 +1,93 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/aspnet-core/Directory.Build.targets b/aspnet-core/Directory.Build.targets index d338319c1..7e9773761 100644 --- a/aspnet-core/Directory.Build.targets +++ b/aspnet-core/Directory.Build.targets @@ -22,43 +22,43 @@ - - - - - - - - - - - + - + - + + + + + + + - + + - - - - - + + + + + + + + @@ -69,25 +69,25 @@ + + - - - - - + - - - - - - + + + + + + + + \ No newline at end of file diff --git a/aspnet-core/Lion.AbpPro.All.sln b/aspnet-core/Lion.AbpPro.All.sln index 66b78632e..b214d9bf6 100644 --- a/aspnet-core/Lion.AbpPro.All.sln +++ b/aspnet-core/Lion.AbpPro.All.sln @@ -398,6 +398,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.ElasticSearch.T EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.EntityFrameworkCore.Tests", "frameworks\test\Lion.AbpPro.EntityFrameworkCore.Mysql.Tests\Lion.AbpPro.EntityFrameworkCore.Tests.csproj", "{FFD342DF-87A5-4642-B694-58714C506883}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.Starter", "frameworks\src\Lion.AbpPro.Starter\Lion.AbpPro.Starter.csproj", "{187AEDA5-8323-45B4-90F6-A2F5574DEB25}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -948,6 +950,10 @@ Global {FFD342DF-87A5-4642-B694-58714C506883}.Debug|Any CPU.Build.0 = Debug|Any CPU {FFD342DF-87A5-4642-B694-58714C506883}.Release|Any CPU.ActiveCfg = Release|Any CPU {FFD342DF-87A5-4642-B694-58714C506883}.Release|Any CPU.Build.0 = Release|Any CPU + {187AEDA5-8323-45B4-90F6-A2F5574DEB25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {187AEDA5-8323-45B4-90F6-A2F5574DEB25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {187AEDA5-8323-45B4-90F6-A2F5574DEB25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {187AEDA5-8323-45B4-90F6-A2F5574DEB25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1128,6 +1134,7 @@ Global {4E9F48F8-4EBB-4D47-BC10-35760EE4F645} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} {A9824877-9F0C-4E33-BEFC-1DD62A365C75} = {EFC415F8-872F-4C7E-8645-31A51481BCFC} {FFD342DF-87A5-4642-B694-58714C506883} = {EFC415F8-872F-4C7E-8645-31A51481BCFC} + {187AEDA5-8323-45B4-90F6-A2F5574DEB25} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.Core/Lion.AbpPro.Core.csproj b/aspnet-core/frameworks/src/Lion.AbpPro.Core/Lion.AbpPro.Core.csproj index 361f69a50..97592ab89 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.Core/Lion.AbpPro.Core.csproj +++ b/aspnet-core/frameworks/src/Lion.AbpPro.Core/Lion.AbpPro.Core.csproj @@ -6,10 +6,6 @@ - - - - diff --git a/aspnet-core/frameworks/src/Lion.AbpPro.EntityFrameworkCore/Lion.AbpPro.EntityFrameworkCore.csproj b/aspnet-core/frameworks/src/Lion.AbpPro.EntityFrameworkCore/Lion.AbpPro.EntityFrameworkCore.csproj index 4c758be28..39ea94568 100644 --- a/aspnet-core/frameworks/src/Lion.AbpPro.EntityFrameworkCore/Lion.AbpPro.EntityFrameworkCore.csproj +++ b/aspnet-core/frameworks/src/Lion.AbpPro.EntityFrameworkCore/Lion.AbpPro.EntityFrameworkCore.csproj @@ -5,6 +5,7 @@ enable enable + CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;EF1001 diff --git a/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Lion.AbpPro.EntityFrameworkCore.Tests.csproj b/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Lion.AbpPro.EntityFrameworkCore.Tests.csproj index 07b404491..f74f83339 100644 --- a/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Lion.AbpPro.EntityFrameworkCore.Tests.csproj +++ b/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Lion.AbpPro.EntityFrameworkCore.Tests.csproj @@ -8,9 +8,9 @@ CS8618;CS0162;CS1584 - - - + + + @@ -21,59 +21,59 @@ - - - - - - + + + + + + - - - + + + - - - - - - + + + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + diff --git a/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Services/BlogAppService.cs b/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Services/BlogAppService.cs index cf6c8a091..b0b925427 100644 --- a/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Services/BlogAppService.cs +++ b/aspnet-core/frameworks/test/Lion.AbpPro.EntityFrameworkCore.Mysql.Tests/Services/BlogAppService.cs @@ -1,134 +1,134 @@ -using System.Diagnostics; -using Lion.AbpPro.EntityFrameworkCore.Tests.Blogs; -using Lion.AbpPro.EntityFrameworkCore.Tests.Entities.Blogs; -using Microsoft.EntityFrameworkCore; -using Volo.Abp; -using Volo.Abp.Application.Services; -using Volo.Abp.Domain.Repositories; -using Volo.Abp.Identity; -using Volo.Abp.Uow; - -namespace Lion.AbpPro.EntityFrameworkCore.Tests.Services; - -public class BlogAppService : ApplicationService -{ - private readonly IBlogRepository _blogRepository; - private readonly IRepository _postRepository; - private readonly IRepository _commentRepository; - private readonly IdentityRoleManager _identityRoleManager; - - public BlogAppService(IBlogRepository blogRepository, IdentityRoleManager identityRoleManager, IRepository postRepository, IRepository commentRepository) - { - _blogRepository = blogRepository; - _identityRoleManager = identityRoleManager; - _postRepository = postRepository; - _commentRepository = commentRepository; - } - - - /// - /// 批量插入10000条数据 - /// - public async Task CreateAsync(int qty = 10000) - { - // mock 数据 - var list = GenFu.GenFu.ListOf(qty); - var stopwatch = new Stopwatch(); - stopwatch.Start(); - await _blogRepository.InsertManyAsync(list); - stopwatch.Stop(); - Logger.LogInformation($"批量插入{list.Count}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); - } - - /// - /// 批量插入10000条数据 - /// - public async Task CreateAllAsync(int qty = 10000) - { - // mock 数据 - var blogs = GenFu.GenFu.ListOf(qty); - var posts = new List(); - var comments = new List(); - // blog和post一对多,post和comment一对多 - // 有主外键关系,所以循环mock数据 - foreach (var blog in blogs) - { - posts.Add(new Post(GuidGenerator.Create(), blog.Id, "name")); - } - - - foreach (var post in posts) - { - comments.Add(new Comment(GuidGenerator.Create(), 1, post.Id, "content")); - } - - var stopwatch = new Stopwatch(); - stopwatch.Start(); - // 需要执行三次,不会因为ef有定义关系而一次性插入posts和comments - await _blogRepository.InsertManyAsync(blogs); - await _postRepository.InsertManyAsync(posts); - await _commentRepository.InsertManyAsync(comments); - stopwatch.Stop(); - Logger.LogInformation($"批量插入blogs:{blogs.Count},posts:{posts.Count},comments:{comments.Count}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); - } - - /// - /// 批量插入10000条数据,并且测试事务是否和其它业务逻辑保持一致 - /// 测试结果:在一个事务内 - /// - public async Task CreateTransactionAsync(int qty = 10) - { - var list = GenFu.GenFu.ListOf(qty); - var stopwatch = new Stopwatch(); - stopwatch.Start(); - await _blogRepository.InsertManyAsync(list); - stopwatch.Stop(); - Logger.LogInformation($"批量插入{list.Count}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); - await _identityRoleManager.CreateAsync(new IdentityRole(GuidGenerator.Create(), GuidGenerator.Create().ToString())); - throw new UserFriendlyException("test"); - } - - /// - /// 批量更新 - /// - /// - public async Task BatchUpdateAsync(int qty = 10000) - { - using (var uow = UnitOfWorkManager.Begin(new AbpUnitOfWorkOptions(true), true)) - { - var list = GenFu.GenFu.ListOf(qty); - await _blogRepository.InsertManyAsync(list); - await uow.CompleteAsync(); - } - - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var dbSet = await _blogRepository.GetDbSetAsync(); - await dbSet.ExecuteUpdateAsync(setters => setters - .SetProperty(x => x.IsDeleted, x => true) - .SetProperty(x => x.Name, x => "test")); - stopwatch.Stop(); - Logger.LogInformation($"批量更新{qty}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); - } - - /// - /// 批量删除 - /// - /// - public async Task BatchDeleteAsync(int qty = 10000) - { - using (var uow = UnitOfWorkManager.Begin(new AbpUnitOfWorkOptions(true), true)) - { - var list = GenFu.GenFu.ListOf(qty); - await _blogRepository.InsertManyAsync(list); - await uow.CompleteAsync(); - } - - var stopwatch = new Stopwatch(); - stopwatch.Start(); - var dbSet = await _blogRepository.GetDbSetAsync(); - await dbSet.ExecuteDeleteAsync(); - stopwatch.Stop(); - Logger.LogInformation($"批量删除{qty}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); - } -} \ No newline at end of file +// using System.Diagnostics; +// using Lion.AbpPro.EntityFrameworkCore.Tests.Blogs; +// using Lion.AbpPro.EntityFrameworkCore.Tests.Entities.Blogs; +// using Microsoft.EntityFrameworkCore; +// using Volo.Abp; +// using Volo.Abp.Application.Services; +// using Volo.Abp.Domain.Repositories; +// using Volo.Abp.Identity; +// using Volo.Abp.Uow; +// +// namespace Lion.AbpPro.EntityFrameworkCore.Tests.Services; +// +// public class BlogAppService : ApplicationService +// { +// private readonly IBlogRepository _blogRepository; +// private readonly IRepository _postRepository; +// private readonly IRepository _commentRepository; +// private readonly IdentityRoleManager _identityRoleManager; +// +// public BlogAppService(IBlogRepository blogRepository, IdentityRoleManager identityRoleManager, IRepository postRepository, IRepository commentRepository) +// { +// _blogRepository = blogRepository; +// _identityRoleManager = identityRoleManager; +// _postRepository = postRepository; +// _commentRepository = commentRepository; +// } +// +// +// /// +// /// 批量插入10000条数据 +// /// +// public async Task CreateAsync(int qty = 10000) +// { +// // mock 数据 +// var list = GenFu.GenFu.ListOf(qty); +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// await _blogRepository.InsertManyAsync(list); +// stopwatch.Stop(); +// Logger.LogInformation($"批量插入{list.Count}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); +// } +// +// /// +// /// 批量插入10000条数据 +// /// +// public async Task CreateAllAsync(int qty = 10000) +// { +// // mock 数据 +// var blogs = GenFu.GenFu.ListOf(qty); +// var posts = new List(); +// var comments = new List(); +// // blog和post一对多,post和comment一对多 +// // 有主外键关系,所以循环mock数据 +// foreach (var blog in blogs) +// { +// posts.Add(new Post(GuidGenerator.Create(), blog.Id, "name")); +// } +// +// +// foreach (var post in posts) +// { +// comments.Add(new Comment(GuidGenerator.Create(), 1, post.Id, "content")); +// } +// +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// // 需要执行三次,不会因为ef有定义关系而一次性插入posts和comments +// await _blogRepository.InsertManyAsync(blogs); +// await _postRepository.InsertManyAsync(posts); +// await _commentRepository.InsertManyAsync(comments); +// stopwatch.Stop(); +// Logger.LogInformation($"批量插入blogs:{blogs.Count},posts:{posts.Count},comments:{comments.Count}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); +// } +// +// /// +// /// 批量插入10000条数据,并且测试事务是否和其它业务逻辑保持一致 +// /// 测试结果:在一个事务内 +// /// +// public async Task CreateTransactionAsync(int qty = 10) +// { +// var list = GenFu.GenFu.ListOf(qty); +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// await _blogRepository.InsertManyAsync(list); +// stopwatch.Stop(); +// Logger.LogInformation($"批量插入{list.Count}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); +// await _identityRoleManager.CreateAsync(new IdentityRole(GuidGenerator.Create(), GuidGenerator.Create().ToString())); +// throw new UserFriendlyException("test"); +// } +// +// /// +// /// 批量更新 +// /// +// /// +// public async Task BatchUpdateAsync(int qty = 10000) +// { +// using (var uow = UnitOfWorkManager.Begin(new AbpUnitOfWorkOptions(true), true)) +// { +// var list = GenFu.GenFu.ListOf(qty); +// await _blogRepository.InsertManyAsync(list); +// await uow.CompleteAsync(); +// } +// +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// var dbSet = await _blogRepository.GetDbSetAsync(); +// await dbSet.ExecuteUpdateAsync(setters => setters +// .SetProperty(x => x.IsDeleted, x => true) +// .SetProperty(x => x.Name, x => "test")); +// stopwatch.Stop(); +// Logger.LogInformation($"批量更新{qty}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); +// } +// +// /// +// /// 批量删除 +// /// +// /// +// public async Task BatchDeleteAsync(int qty = 10000) +// { +// using (var uow = UnitOfWorkManager.Begin(new AbpUnitOfWorkOptions(true), true)) +// { +// var list = GenFu.GenFu.ListOf(qty); +// await _blogRepository.InsertManyAsync(list); +// await uow.CompleteAsync(); +// } +// +// var stopwatch = new Stopwatch(); +// stopwatch.Start(); +// var dbSet = await _blogRepository.GetDbSetAsync(); +// await dbSet.ExecuteDeleteAsync(); +// stopwatch.Stop(); +// Logger.LogInformation($"批量删除{qty}条,耗时(单位:毫秒):{stopwatch.ElapsedMilliseconds}"); +// } +// } \ No newline at end of file diff --git a/aspnet-core/modules/BasicManagement/host/Lion.AbpPro.BasicManagement.HttpApi.Host/Lion.AbpPro.BasicManagement.HttpApi.Host.csproj b/aspnet-core/modules/BasicManagement/host/Lion.AbpPro.BasicManagement.HttpApi.Host/Lion.AbpPro.BasicManagement.HttpApi.Host.csproj index 3911b0797..4d163135e 100644 --- a/aspnet-core/modules/BasicManagement/host/Lion.AbpPro.BasicManagement.HttpApi.Host/Lion.AbpPro.BasicManagement.HttpApi.Host.csproj +++ b/aspnet-core/modules/BasicManagement/host/Lion.AbpPro.BasicManagement.HttpApi.Host/Lion.AbpPro.BasicManagement.HttpApi.Host.csproj @@ -10,7 +10,6 @@ - diff --git a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Lion.AbpPro.BasicManagement.Application.csproj b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Lion.AbpPro.BasicManagement.Application.csproj index 9f4d46e85..7d3ce82dc 100644 --- a/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Lion.AbpPro.BasicManagement.Application.csproj +++ b/aspnet-core/modules/BasicManagement/src/Lion.AbpPro.BasicManagement.Application/Lion.AbpPro.BasicManagement.Application.csproj @@ -16,9 +16,9 @@ - - - + + + diff --git a/aspnet-core/modules/FileManagement/host/Lion.AbpPro.FileManagement.HttpApi.Host/Lion.AbpPro.FileManagement.HttpApi.Host.csproj b/aspnet-core/modules/FileManagement/host/Lion.AbpPro.FileManagement.HttpApi.Host/Lion.AbpPro.FileManagement.HttpApi.Host.csproj index ec3c0c71a..ce03cd9eb 100644 --- a/aspnet-core/modules/FileManagement/host/Lion.AbpPro.FileManagement.HttpApi.Host/Lion.AbpPro.FileManagement.HttpApi.Host.csproj +++ b/aspnet-core/modules/FileManagement/host/Lion.AbpPro.FileManagement.HttpApi.Host/Lion.AbpPro.FileManagement.HttpApi.Host.csproj @@ -17,7 +17,7 @@ - + diff --git a/aspnet-core/modules/NotificationManagement/host/Lion.AbpPro.NotificationManagement.HttpApi.Host/Lion.AbpPro.NotificationManagement.HttpApi.Host.csproj b/aspnet-core/modules/NotificationManagement/host/Lion.AbpPro.NotificationManagement.HttpApi.Host/Lion.AbpPro.NotificationManagement.HttpApi.Host.csproj index 496755b51..2e2e91d37 100644 --- a/aspnet-core/modules/NotificationManagement/host/Lion.AbpPro.NotificationManagement.HttpApi.Host/Lion.AbpPro.NotificationManagement.HttpApi.Host.csproj +++ b/aspnet-core/modules/NotificationManagement/host/Lion.AbpPro.NotificationManagement.HttpApi.Host/Lion.AbpPro.NotificationManagement.HttpApi.Host.csproj @@ -18,7 +18,6 @@ - diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.Configure.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.Configure.cs index 789cf38c5..8eca0b04b 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.Configure.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.Configure.cs @@ -112,7 +112,7 @@ private void ConfigureCache(ServiceConfigurationContext context) Configure( options => { options.KeyPrefix = "AbpPro:"; }); var configuration = context.Services.GetConfiguration(); - var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); + var redis = ConnectionMultiplexer.Connect(configuration.GetValue("Redis:Configuration")); context.Services .AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "AbpPro-Protection-Keys"); diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs index 0b60928f2..93676afe0 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs @@ -6,7 +6,10 @@ public static class RecurringJobsExtensions { public static void CreateRecurringJob(this ApplicationInitializationContext context) { - RecurringJob.AddOrUpdate("测试Job", t => t.ExecuteAsync(), CronType.Minute(1),TimeZoneInfo.Local); + RecurringJob.AddOrUpdate("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions() + { + TimeZone = TimeZoneInfo.Local + }); } } } \ No newline at end of file diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs index 6c50ca58a..067888082 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/GlobalUsings.cs @@ -11,6 +11,7 @@ global using Hangfire.Common; global using Hangfire.Dashboard; global using Hangfire.Redis; +global using Hangfire.Redis.StackExchange; global using Hangfire.States; global using Hangfire.Storage; global using Lion.AbpPro.CAP; diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj index cf871f7c5..e7314fa12 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj @@ -9,7 +9,6 @@ - diff --git a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Startup.cs b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Startup.cs index e0a3a8414..c8e3847f7 100644 --- a/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Startup.cs +++ b/aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Startup.cs @@ -25,6 +25,7 @@ public void Configure(IApplicationBuilder app,IHostApplicationLifetime lifetime) /// /// 程序首次访问接口速度慢,事先预热 /// + [Obsolete("请使用Lion.AbpPro.Starter模块,实现IAbpProStarterContributor")] private void ConfigurePreheat() { var url = _configuration.GetValue("App:SelfUrl"); diff --git a/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj index 508ae217b..17db6032d 100644 --- a/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj +++ b/aspnet-core/services/src/Lion.AbpPro.FreeSqlRepository/Lion.AbpPro.FreeSqlRepository.csproj @@ -7,7 +7,7 @@ - + diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs index 5bcfd1d75..d83618ba5 100644 --- a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/GlobalUsings.cs @@ -9,7 +9,9 @@ global using System.Text; global using System.Text.RegularExpressions; global using Consul; +global using Lion.AbpPro; global using Lion.AbpPro.Core; +global using Lion.AbpPro.Localization; global using Microsoft.AspNetCore.Builder; global using Microsoft.AspNetCore.Cors; global using Microsoft.AspNetCore.Http; @@ -18,9 +20,11 @@ global using Microsoft.AspNetCore.Mvc.Abstractions; global using Microsoft.AspNetCore.Mvc.ApiExplorer; global using Microsoft.AspNetCore.Mvc.Filters; +global using Microsoft.EntityFrameworkCore; global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Hosting; +global using Microsoft.Extensions.Localization; global using Microsoft.Extensions.Logging; global using Microsoft.Extensions.Logging.Abstractions; global using Microsoft.Extensions.Options; @@ -36,6 +40,7 @@ global using Volo.Abp.AspNetCore.ExceptionHandling; global using Volo.Abp.AspNetCore.Mvc; global using Volo.Abp.AspNetCore.Mvc.AntiForgery; +global using Volo.Abp.AspNetCore.Mvc.ExceptionHandling; global using Volo.Abp.Authorization; global using Volo.Abp.Autofac; global using Volo.Abp.DependencyInjection; @@ -44,6 +49,7 @@ global using Volo.Abp.Http; global using Volo.Abp.Json; global using Volo.Abp.Localization; +global using Volo.Abp.Localization.ExceptionHandling; global using Volo.Abp.Modularity; global using Volo.Abp.Swashbuckle; global using Volo.Abp.UI.Navigation.Urls; diff --git a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/AbpProExceptionFilter.cs b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/AbpProExceptionFilter.cs index bcbff1ffa..119cc1ddc 100644 --- a/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/AbpProExceptionFilter.cs +++ b/aspnet-core/shared/Lion.AbpPro.Shared.Hosting.Microservices/Microsoft/AspNetCore/Mvc/Filters/AbpProExceptionFilter.cs @@ -1,40 +1,53 @@ -using System.Text; -using Lion.AbpPro; -using Lion.AbpPro.Localization; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Localization; -using Volo.Abp.Localization.ExceptionHandling; - namespace Microsoft.AspNetCore.Mvc.Filters; -public sealed class AbpProExceptionFilter : IAsyncExceptionFilter, ITransientDependency +[Dependency(ReplaceServices = true)] +[ExposeServices(typeof(AbpExceptionFilter))] +public class AbpProExceptionFilter : AbpExceptionFilter { - public async Task OnExceptionAsync(ExceptionContext context) + protected override bool ShouldHandleException(ExceptionContext context) { - if (!ShouldHandleException(context)) - { - return; - } + return IsWrapResult(context) || base.ShouldHandleException(context); + } - await HandleAndWrapException(context); + protected override async Task HandleAndWrapException(ExceptionContext context) + { + LoggerException(context); + if (WrapResultHandler(context)) return; + await DefaultHandlerAsync(context); } - private bool ShouldHandleException(ExceptionContext context) + private void LoggerException(ExceptionContext context) { - if (context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) + var exceptionHandlingOptions = context.GetRequiredService>().Value; + var exceptionToErrorInfoConverter = context.GetRequiredService(); + var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, options => { - return true; - } + options.SendExceptionsDetailsToClients = exceptionHandlingOptions.SendExceptionsDetailsToClients; + options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; + }); - if (context.ActionDescriptor.GetMethodInfo().GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) - { - return true; - } + var logger = context.GetService>(NullLogger.Instance)!; + var logLevel = context.Exception.GetLogLevel(); + logger.LogException(context.Exception, logLevel); + } - return false; + /// + /// webapi有WrapResult特性标签处理逻辑 + /// + private bool WrapResultHandler(ExceptionContext context) + { + if (!IsWrapResult(context)) return false; + + context.HttpContext.Response.StatusCode = 200; + var result = SimplifyMessage(context); + context.Result = new ObjectResult(result); + return true; } - private async Task HandleAndWrapException(ExceptionContext context) + /// + /// 默认异常处理逻辑 + /// + private async Task DefaultHandlerAsync(ExceptionContext context) { var exceptionHandlingOptions = context.GetRequiredService>().Value; var exceptionToErrorInfoConverter = context.GetRequiredService(); @@ -44,23 +57,34 @@ private async Task HandleAndWrapException(ExceptionContext context) options.SendStackTraceToClients = exceptionHandlingOptions.SendStackTraceToClients; }); - var logLevel = context.Exception.GetLogLevel(); - - var remoteServiceErrorInfoBuilder = new StringBuilder(); - remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); - remoteServiceErrorInfoBuilder.AppendLine(context.GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); - - var logger = context.GetService>(NullLogger.Instance); + if (context.Exception is AbpAuthorizationException) + { + await context.HttpContext.RequestServices.GetRequiredService() + .HandleAsync(context.Exception.As(), context.HttpContext); + } + else + { + context.HttpContext.Response.Headers.Add(AbpHttpConsts.AbpErrorFormat, "true"); + context.HttpContext.Response.StatusCode = (int)context + .GetRequiredService() + .GetStatusCode(context.HttpContext, context.Exception); + context.Result = new ObjectResult(new RemoteServiceErrorResponse(remoteServiceErrorInfo)); + } + } - logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); + private bool IsWrapResult(ExceptionContext context) + { + if (context.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) + { + return true; + } - logger.LogException(context.Exception, logLevel); + if (context.ActionDescriptor.GetMethodInfo().GetCustomAttributes(typeof(WrapResultAttribute), true).Any()) + { + return true; + } - await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); - context.HttpContext.Response.StatusCode = 200; - var result = SimplifyMessage(context); - context.Result = new ObjectResult(result); - context.Exception = null; //Handled! + return false; } private WrapResult SimplifyMessage(ExceptionContext context) diff --git a/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.Volo.targets b/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.Volo.targets index 3f5f0b0d6..475b19540 100644 --- a/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.Volo.targets +++ b/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.Volo.targets @@ -1,93 +1,93 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.targets b/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.targets index 4577e2814..cbd5e8a50 100644 --- a/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.targets +++ b/templates/abp-vnext-pro-nuget-all/aspnet-core/Directory.Build.targets @@ -16,45 +16,44 @@ https://blog-resouce.oss-cn-shenzhen.aliyuncs.com/images/abp/06.jpg - - - - - - - - - - - - + - + - + + + + + + + - + + - - - - - + + + + + + + + @@ -65,27 +64,25 @@ + + - - - - - - - + - + + - - - - + + + + + \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs b/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs index 4eafe81bd..31a9ffabd 100644 --- a/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs +++ b/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs @@ -1,14 +1,15 @@ using MyCompanyName.MyProjectName.Jobs; -namespace MyCompanyName.MyProjectName.Extensions +namespace MyCompanyName.MyProjectName.Extensions.Hangfire { public static class RecurringJobsExtensions { public static void CreateRecurringJob(this ApplicationInitializationContext context) { - using var scope = context.ServiceProvider.CreateScope(); - var testJob = scope.ServiceProvider.GetService(); - RecurringJob.AddOrUpdate("测试Job", () => testJob.ExecuteAsync(), CronType.Minute(1), TimeZoneInfo.Local); + RecurringJob.AddOrUpdate("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions() + { + TimeZone = TimeZoneInfo.Local + }); } } } \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs b/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs index 4df26a500..934b3597d 100644 --- a/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs +++ b/templates/abp-vnext-pro-nuget-all/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs @@ -69,7 +69,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex private void ConfigurationSignalR(ServiceConfigurationContext context) { - var redisConnection = context.Services.GetConfiguration()["Redis:Configuration"]; + var redisConnection = context.Services.GetConfiguration().GetValue("Redis:Configuration"); if (redisConnection.IsNullOrWhiteSpace()) { diff --git a/templates/abp-vnext-pro-nuget-all/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj b/templates/abp-vnext-pro-nuget-all/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj index b45abefd9..9c331342c 100644 --- a/templates/abp-vnext-pro-nuget-all/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj +++ b/templates/abp-vnext-pro-nuget-all/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj @@ -7,7 +7,7 @@ - + diff --git a/templates/abp-vnext-pro-nuget-module/Directory.Build.Volo.targets b/templates/abp-vnext-pro-nuget-module/Directory.Build.Volo.targets index 3f292e0e6..3188a25e9 100644 --- a/templates/abp-vnext-pro-nuget-module/Directory.Build.Volo.targets +++ b/templates/abp-vnext-pro-nuget-module/Directory.Build.Volo.targets @@ -1,92 +1,92 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-module/Directory.Build.targets b/templates/abp-vnext-pro-nuget-module/Directory.Build.targets index 93c0d598b..e72756eff 100644 --- a/templates/abp-vnext-pro-nuget-module/Directory.Build.targets +++ b/templates/abp-vnext-pro-nuget-module/Directory.Build.targets @@ -16,43 +16,43 @@ - - - - - - - - - - - + - + - + + + + + + + - + + - - - - - + + + + + + + + @@ -63,27 +63,25 @@ + + - - - - - - - + - + + - - - - + + + + + \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.Volo.targets b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.Volo.targets index 3f5f0b0d6..475b19540 100644 --- a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.Volo.targets +++ b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.Volo.targets @@ -1,93 +1,93 @@  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.targets b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.targets index 8e0f5c572..411bcf4b9 100644 --- a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.targets +++ b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/Directory.Build.targets @@ -13,45 +13,44 @@ true - - - - - - - - - - - - + - + - + + + + + + + - + + - - - - - + + + + + + + + @@ -62,27 +61,25 @@ + + - - - - - - - + - + + - - - - + + + + + \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs index 4eafe81bd..31a9ffabd 100644 --- a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs +++ b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/Extensions/Hangfire/RecurringJobsExtensions.cs @@ -1,14 +1,15 @@ using MyCompanyName.MyProjectName.Jobs; -namespace MyCompanyName.MyProjectName.Extensions +namespace MyCompanyName.MyProjectName.Extensions.Hangfire { public static class RecurringJobsExtensions { public static void CreateRecurringJob(this ApplicationInitializationContext context) { - using var scope = context.ServiceProvider.CreateScope(); - var testJob = scope.ServiceProvider.GetService(); - RecurringJob.AddOrUpdate("测试Job", () => testJob.ExecuteAsync(), CronType.Minute(1), TimeZoneInfo.Local); + RecurringJob.AddOrUpdate("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions() + { + TimeZone = TimeZoneInfo.Local + }); } } } \ No newline at end of file diff --git a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs index 6a6d18c91..9086e9d89 100644 --- a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs +++ b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/host/MyCompanyName.MyProjectName.HttpApi.Host/MyProjectNameHttpApiHostModule.cs @@ -62,7 +62,7 @@ public override void OnApplicationInitialization(ApplicationInitializationContex } private void ConfigurationSignalR(ServiceConfigurationContext context) { - var redisConnection = context.Services.GetConfiguration()["Redis:Configuration"]; + var redisConnection = context.Services.GetConfiguration().GetValue("Redis:Configuration"); if (redisConnection.IsNullOrWhiteSpace()) { diff --git a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj index 416264449..1e658f67f 100644 --- a/templates/abp-vnext-pro-nuget-simplify/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj +++ b/templates/abp-vnext-pro-nuget-simplify/aspnet-core/src/MyCompanyName.MyProjectName.FreeSqlRepository/MyCompanyName.MyProjectName.FreeSqlRepository.csproj @@ -7,7 +7,7 @@ - +