From 3ffb26772bcfab82550d8f592d719fb234f6ded7 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Tue, 23 Mar 2021 17:08:19 +0800 Subject: [PATCH] add modules LINGYUN.Abp.AspNetCore.Mvc.Client --- aspnet-core/LINGYUN.MicroService.All.sln | 11 ++- aspnet-core/LINGYUN.MicroService.Common.sln | 7 ++ .../LINGYUN.Abp.AspNetCore.Mvc.Client.csproj | 16 ++++ ...GYUN.Abp.AspNetCore.Mvc.Client.csproj.user | 6 ++ .../AbpAspNetCoreMvcClientCacheOptions.cs | 16 ++++ .../Client/AbpAspNetCoreMvcClientModule.cs | 21 ++++ ...MvcCachedApplicationConfigurationClient.cs | 96 +++++++++++++++++++ ...hedApplicationConfigurationClientHelper.cs | 14 +++ ...tionConfigurationCacheResetEventHandler.cs | 34 +++++++ .../Properties/launchSettings.json | 27 ++++++ .../README.md | 36 +++++++ ...N.Abp.SettingManagement.Application.csproj | 1 + .../SettingManagement/SettingAppService.cs | 17 ++++ 13 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj.user create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCacheOptions.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClientHelper.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCurrentApplicationConfigurationCacheResetEventHandler.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/Properties/launchSettings.json create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/README.md diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index 0d0459cd5..c3e00e3aa 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -286,9 +286,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.OssManagement.S EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Features.LimitValidation.Redis.Client", "modules\common\LINGYUN.Abp.Features.LimitValidation.Redis.Client\LINGYUN.Abp.Features.LimitValidation.Redis.Client.csproj", "{48DE251A-3482-4934-BC26-F99D2235AC9F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Location.Tencent.Tests", "tests\LINGYUN.Abp.Location.Tencent.Tests\LINGYUN.Abp.Location.Tencent.Tests.csproj", "{94B47385-E47F-4FD7-A3A9-A7AA122EFC93}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Location.Tencent.Tests", "tests\LINGYUN.Abp.Location.Tencent.Tests\LINGYUN.Abp.Location.Tencent.Tests.csproj", "{94B47385-E47F-4FD7-A3A9-A7AA122EFC93}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Location.Baidu.Tests", "tests\LINGYUN.Abp.Location.Baidu.Tests\LINGYUN.Abp.Location.Baidu.Tests.csproj", "{C892CD81-50AE-49E5-BF44-A0C28A1614CC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Location.Baidu.Tests", "tests\LINGYUN.Abp.Location.Baidu.Tests\LINGYUN.Abp.Location.Baidu.Tests.csproj", "{C892CD81-50AE-49E5-BF44-A0C28A1614CC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.AspNetCore.Mvc.Client", "modules\common\LINGYUN.Abp.AspNetCore.Mvc.Client\LINGYUN.Abp.AspNetCore.Mvc.Client.csproj", "{EEF03CC6-1013-4AAF-BEED-BB4BA5021039}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -764,6 +766,10 @@ Global {C892CD81-50AE-49E5-BF44-A0C28A1614CC}.Debug|Any CPU.Build.0 = Debug|Any CPU {C892CD81-50AE-49E5-BF44-A0C28A1614CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {C892CD81-50AE-49E5-BF44-A0C28A1614CC}.Release|Any CPU.Build.0 = Release|Any CPU + {EEF03CC6-1013-4AAF-BEED-BB4BA5021039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EEF03CC6-1013-4AAF-BEED-BB4BA5021039}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EEF03CC6-1013-4AAF-BEED-BB4BA5021039}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EEF03CC6-1013-4AAF-BEED-BB4BA5021039}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -908,6 +914,7 @@ Global {48DE251A-3482-4934-BC26-F99D2235AC9F} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} {94B47385-E47F-4FD7-A3A9-A7AA122EFC93} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F} {C892CD81-50AE-49E5-BF44-A0C28A1614CC} = {370D7CD5-1E17-4F3D-BBFA-03429F6D4F2F} + {EEF03CC6-1013-4AAF-BEED-BB4BA5021039} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/LINGYUN.MicroService.Common.sln b/aspnet-core/LINGYUN.MicroService.Common.sln index e9df59cff..f106c402f 100644 --- a/aspnet-core/LINGYUN.MicroService.Common.sln +++ b/aspnet-core/LINGYUN.MicroService.Common.sln @@ -115,6 +115,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Location.Baidu. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Location.Tencent.Tests", "tests\LINGYUN.Abp.Location.Tencent.Tests\LINGYUN.Abp.Location.Tencent.Tests.csproj", "{1B494EA1-28CF-4A61-B0BE-70BBA425C316}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.AspNetCore.Mvc.Client", "modules\common\LINGYUN.Abp.AspNetCore.Mvc.Client\LINGYUN.Abp.AspNetCore.Mvc.Client.csproj", "{7F767ACF-754A-4EBC-8936-3C1402B6EF82}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -301,6 +303,10 @@ Global {1B494EA1-28CF-4A61-B0BE-70BBA425C316}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B494EA1-28CF-4A61-B0BE-70BBA425C316}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B494EA1-28CF-4A61-B0BE-70BBA425C316}.Release|Any CPU.Build.0 = Release|Any CPU + {7F767ACF-754A-4EBC-8936-3C1402B6EF82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F767ACF-754A-4EBC-8936-3C1402B6EF82}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F767ACF-754A-4EBC-8936-3C1402B6EF82}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F767ACF-754A-4EBC-8936-3C1402B6EF82}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -360,6 +366,7 @@ Global {93DD5A05-B67A-4E11-BB56-F6B4E7F1489C} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {221725FF-6C01-4F41-9F29-AC04C7D52611} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} {1B494EA1-28CF-4A61-B0BE-70BBA425C316} = {B86C21A4-73B7-471E-B73A-B4B905EC9435} + {7F767ACF-754A-4EBC-8936-3C1402B6EF82} = {086BE5BE-8594-4DA7-8819-935FEF76DABD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {06C707C6-02C0-411A-AD3B-2D0E13787CB8} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj new file mode 100644 index 000000000..32cd2d483 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj @@ -0,0 +1,16 @@ + + + + + + net5.0 + + Library + + + + + + + + diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj.user b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj.user new file mode 100644 index 000000000..cff74a90e --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN.Abp.AspNetCore.Mvc.Client.csproj.user @@ -0,0 +1,6 @@ + + + + IIS Express + + \ No newline at end of file diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCacheOptions.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCacheOptions.cs new file mode 100644 index 000000000..7172ebec8 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientCacheOptions.cs @@ -0,0 +1,16 @@ +namespace LINGYUN.Abp.AspNetCore.Mvc.Client +{ + public class AbpAspNetCoreMvcClientCacheOptions + { + /// + /// 用户缓存过期时间, 单位: 秒 + /// 默认: 300 + /// + public int UserCacheExpirationSeconds { get; set; } = 300; + /// + /// 匿名用户缓存过期时间, 单位: 秒 + /// 默认: 300 + /// + public int AnonymousCacheExpirationSeconds { get; set; } = 300; + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs new file mode 100644 index 000000000..3fec75b56 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/AbpAspNetCoreMvcClientModule.cs @@ -0,0 +1,21 @@ +using Microsoft.Extensions.DependencyInjection; +using System; +using Volo.Abp.AspNetCore.Mvc.Client; +using Volo.Abp.EventBus; +using Volo.Abp.Modularity; + +namespace LINGYUN.Abp.AspNetCore.Mvc.Client +{ + [DependsOn( + typeof(AbpAspNetCoreMvcClientCommonModule), + typeof(AbpEventBusModule) + )] + public class AbpAspNetCoreMvcClientModule : AbpModule + { + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(configuration.GetSection("AbpMvcClient:Cache")); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs new file mode 100644 index 000000000..b9c7d2b5e --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClient.cs @@ -0,0 +1,96 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Options; +using System; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.AspNetCore.Mvc.Client; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client.DynamicProxying; +using Volo.Abp.Threading; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.AspNetCore.Mvc.Client +{ + [ExposeServices( + typeof(MvcCachedApplicationConfigurationClient), + typeof(ICachedApplicationConfigurationClient), + typeof(IAsyncInitialize) + )] + public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency + { + protected IHttpContextAccessor HttpContextAccessor { get; } + protected IHttpClientProxy Proxy { get; } + protected ICurrentUser CurrentUser { get; } + protected IDistributedCache Cache { get; } + protected AbpAspNetCoreMvcClientCacheOptions Options { get; } + + public MvcCachedApplicationConfigurationClient( + IDistributedCache cache, + IHttpClientProxy proxy, + ICurrentUser currentUser, + IHttpContextAccessor httpContextAccessor, + IOptions options) + { + Proxy = proxy; + CurrentUser = currentUser; + HttpContextAccessor = httpContextAccessor; + Cache = cache; + Options = options.Value; + } + + public async Task InitializeAsync() + { + await GetAsync(); + } + + public async Task GetAsync() + { + var cacheKey = CreateCacheKey(); + var httpContext = HttpContextAccessor?.HttpContext; + + if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) + { + return configuration; + } + + configuration = await Cache.GetOrAddAsync( + cacheKey, + async () => await Proxy.Service.GetAsync(), + () => new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(CurrentUser.IsAuthenticated + ? Options.UserCacheExpirationSeconds + : Options.AnonymousCacheExpirationSeconds) + } + ); + + if (httpContext != null) + { + httpContext.Items[cacheKey] = configuration; + } + + return configuration; + } + + public ApplicationConfigurationDto Get() + { + var cacheKey = CreateCacheKey(); + var httpContext = HttpContextAccessor?.HttpContext; + + if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration) + { + return configuration; + } + + return AsyncHelper.RunSync(GetAsync); + } + + protected virtual string CreateCacheKey() + { + return MvcCachedApplicationConfigurationClientHelper.CreateCacheKey(CurrentUser); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClientHelper.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClientHelper.cs new file mode 100644 index 000000000..1f0761f66 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCachedApplicationConfigurationClientHelper.cs @@ -0,0 +1,14 @@ +using System.Globalization; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.AspNetCore.Mvc.Client +{ + internal static class MvcCachedApplicationConfigurationClientHelper + { + public static string CreateCacheKey(ICurrentUser currentUser) + { + var userKey = currentUser.Id?.ToString("N") ?? "Anonymous"; + return $"ApplicationConfiguration_{userKey}_{CultureInfo.CurrentUICulture.Name}"; + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCurrentApplicationConfigurationCacheResetEventHandler.cs b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCurrentApplicationConfigurationCacheResetEventHandler.cs new file mode 100644 index 000000000..a8ca5685e --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/LINGYUN/Abp/AspNetCore/Mvc/Client/MvcCurrentApplicationConfigurationCacheResetEventHandler.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.Users; + +namespace LINGYUN.Abp.AspNetCore.Mvc.Client +{ + public class MvcCurrentApplicationConfigurationCacheResetEventHandler : + IDistributedEventHandler, + ITransientDependency + { + protected ICurrentUser CurrentUser { get; } + protected IDistributedCache Cache { get; } + + public MvcCurrentApplicationConfigurationCacheResetEventHandler(ICurrentUser currentUser, + IDistributedCache cache) + { + CurrentUser = currentUser; + Cache = cache; + } + + public virtual async Task HandleEventAsync(CurrentApplicationConfigurationCacheResetEventData eventData) + { + await Cache.RemoveAsync(CreateCacheKey()); + } + + protected virtual string CreateCacheKey() + { + return MvcCachedApplicationConfigurationClientHelper.CreateCacheKey(CurrentUser); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/Properties/launchSettings.json b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/Properties/launchSettings.json new file mode 100644 index 000000000..7cd042c63 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:41514/", + "sslPort": 44331 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "LINGYUN.Abp.AspNetCore.Mvc.Client": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/README.md b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/README.md new file mode 100644 index 000000000..3c674aa13 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.AspNetCore.Mvc.Client/README.md @@ -0,0 +1,36 @@ +# LINGYUN.Abp.AspNetCore.Mvc.Client + +参照 Volo.Abp.AspNetCore.Mvc.Client 进行重写 + +实现可配置的用户配置缓存时间 +实现订阅配置刷新事件清除用户配置缓存 +实现基于用户缓存的权限、特性、配置、本地化、语言接口 +引用 LINGYUN.Abp.MultiTenancy.RemoteService 可实现多租户接口 +完全脱离具体数据库接口 + +#### 注意 + + +## 配置使用 + + +``` json + +{ + "AbpMvcClient": { + "Cache": { + "UserCacheExpirationSeconds": 300, + "AnonymousCacheExpirationSeconds": 300 + } + } +} + +``` + +```csharp +[DependsOn(typeof(AbpAspNetCoreMvcClientModule))] +public class YouProjectModule : AbpModule +{ + // other +} +``` \ No newline at end of file diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN.Abp.SettingManagement.Application.csproj b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN.Abp.SettingManagement.Application.csproj index 9c8cd2e38..15b0643f1 100644 --- a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN.Abp.SettingManagement.Application.csproj +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN.Abp.SettingManagement.Application.csproj @@ -7,6 +7,7 @@ + diff --git a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs index 09b10dc63..9eb4774ca 100644 --- a/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs +++ b/aspnet-core/modules/settings/LINGYUN.Abp.SettingManagement.Application/LINGYUN/Abp/SettingManagement/SettingAppService.cs @@ -17,6 +17,8 @@ using Volo.Abp.SettingManagement.Localization; using Volo.Abp.Settings; using Volo.Abp.Timing; using Volo.Abp.Users; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; namespace LINGYUN.Abp.SettingManagement { @@ -25,17 +27,20 @@ namespace LINGYUN.Abp.SettingManagement { protected AbpLocalizationOptions LocalizationOptions { get; } + protected IDistributedEventBus EventBus { get; } protected ISettingManager SettingManager { get; } protected ISettingDefinitionManager SettingDefinitionManager { get; } protected IDistributedCache Cache { get; } public SettingAppService( + IDistributedEventBus eventBus, ISettingManager settingManager, IDistributedCache cache, IOptions localizationOptions, ISettingDefinitionManager settingDefinitionManager) { Cache = cache; + EventBus = eventBus; SettingManager = settingManager; SettingDefinitionManager = settingDefinitionManager; LocalizationOptions = localizationOptions.Value; @@ -50,6 +55,12 @@ namespace LINGYUN.Abp.SettingManagement await SettingManager.SetGlobalAsync(setting.Name, setting.Value); } + CurrentUnitOfWork.OnCompleted(async () => + { + // 发送刷新用户缓存事件 + await EventBus.PublishAsync(new CurrentApplicationConfigurationCacheResetEventData()); + }); + await CurrentUnitOfWork.SaveChangesAsync(); } @@ -63,6 +74,12 @@ namespace LINGYUN.Abp.SettingManagement await SettingManager.SetForTenantAsync(CurrentTenant.GetId(), setting.Name, setting.Value); } + CurrentUnitOfWork.OnCompleted(async () => + { + // 发送刷新用户缓存事件 + await EventBus.PublishAsync(new CurrentApplicationConfigurationCacheResetEventData()); + }); + await CurrentUnitOfWork.SaveChangesAsync(); } }