From d98966052b4aa657d3e7e92e341b1c9da6b53b12 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Wed, 26 Aug 2020 15:04:22 +0800 Subject: [PATCH] add abp-caching-stack-exchange-redis module --- aspnet-core/LINGYUN.MicroService.sln | 7 ---- .../appsettings.Development.json | 7 ++-- .../appsettings.Development.json | 7 ++-- .../appsettings.Development.json | 7 ++-- .../appsettings.Development.json | 7 ++-- .../appsettings.Development.json | 7 ++-- .../AuthIdentityServerModule.cs | 28 ++++++++++----- .../AuthServer.Host/AuthServer.Host.csproj | 7 ++-- .../BackendAdminHostModule.cs | 28 ++++++++++----- .../LINGYUN.BackendAdminApp.Host.csproj | 7 ++-- .../ApiGatewayHttpApiHostModule.cs | 36 +++++++++++++++---- .../LINGYUN.ApiGateway.HttpApi.Host.csproj | 13 +++---- ...YUN.Abp.MessageService.HttpApi.Host.csproj | 7 ++-- .../AbpMessageServiceHttpApiHostModule.cs | 35 ++++++++++++++---- .../AppPlatformHttpApiHostModule.cs | 27 ++++++++++---- .../LINGYUN.Platform.HttpApi.Host.csproj | 7 ++-- 16 files changed, 160 insertions(+), 77 deletions(-) diff --git a/aspnet-core/LINGYUN.MicroService.sln b/aspnet-core/LINGYUN.MicroService.sln index 9cbfa579d..94df85523 100644 --- a/aspnet-core/LINGYUN.MicroService.sln +++ b/aspnet-core/LINGYUN.MicroService.sln @@ -213,8 +213,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.Domain EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.EntityFrameworkCore", "modules\identity\LINGYUN.Abp.Identity.EntityFrameworkCore\LINGYUN.Abp.Identity.EntityFrameworkCore.csproj", "{6FE7E243-2D99-4567-8786-6C9283D608EF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.AspNetCore.Mvc", "modules\common\LINGYUN.Abp.Notifications.AspNetCore.Mvc\LINGYUN.Abp.Notifications.AspNetCore.Mvc.csproj", "{1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -569,10 +567,6 @@ Global {6FE7E243-2D99-4567-8786-6C9283D608EF}.Debug|Any CPU.Build.0 = Debug|Any CPU {6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.Build.0 = Release|Any CPU - {1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -680,7 +674,6 @@ Global {5D0ED1FC-3A7C-4531-9512-832E73AD9555} = {0439B173-F41E-4CE0-A44A-CCB70328F272} {2BF7FB73-0C62-4ECF-99F0-0583855D2777} = {52B5D4F7-237B-4E0A-A167-68442164F70A} {6FE7E243-2D99-4567-8786-6C9283D608EF} = {52B5D4F7-237B-4E0A-A167-68442164F70A} - {1A9C06D0-1A12-48C6-B3F6-F2DBC66AA355} = {8AC72641-30D3-4ACF-89FA-808FADC55C2E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} diff --git a/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json b/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json index aa82f1d34..171925d67 100644 --- a/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json +++ b/aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json @@ -48,9 +48,10 @@ "VirtualHost": "multi.service.test" } }, - "RedisCache": { - "ConnectString": "127.0.0.1", - "RedisPrefix": "AuthServer" + "Redis": { + "Configuration": "127.0.0.1", + "InstanceName": "LINGYUN.AbpApplication", + "DefaultDatabase": 10 }, "AuthServer": { "Authority": "http://localhost:44385/", diff --git a/aspnet-core/configuration/admin/LINGYUN.BackendAdminApp.Host/appsettings.Development.json b/aspnet-core/configuration/admin/LINGYUN.BackendAdminApp.Host/appsettings.Development.json index 20218b346..a8d83e330 100644 --- a/aspnet-core/configuration/admin/LINGYUN.BackendAdminApp.Host/appsettings.Development.json +++ b/aspnet-core/configuration/admin/LINGYUN.BackendAdminApp.Host/appsettings.Development.json @@ -69,9 +69,10 @@ "VirtualHost": "Name of your RabbitMQ server VirtualHost" } }, - "RedisCache": { - "RedisPrefix": "Platform_Test_Cache", - "ConnectString": "127.0.0.1" + "Redis": { + "Configuration": "127.0.0.1", + "InstanceName": "LINGYUN.AbpApplication", + "DefaultDatabase": 10 }, "AuthServer": { "Authority": "http://localhost:44385/", diff --git a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json index e5e3214da..1542e3bb5 100644 --- a/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json @@ -6,9 +6,10 @@ "AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", "AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" }, - "RedisCache": { - "RedisPrefix": "ApiGateway_Test_Cache", - "ConnectString": "127.0.0.1" + "Redis": { + "Configuration": "127.0.0.1", + "InstanceName": "LINGYUN.AbpApplication", + "DefaultDatabase": 10 }, "CAP": { "EventBus": { diff --git a/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json index 74da04c9c..97b761933 100644 --- a/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json @@ -6,9 +6,10 @@ "AbpSettingManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456", "AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456" }, - "RedisCache": { - "RedisPrefix": "Platform_Test_Cache", - "ConnectString": "127.0.0.1" + "Redis": { + "Configuration": "127.0.0.1", + "InstanceName": "LINGYUN.AbpApplication", + "DefaultDatabase": 10 }, "AuthServer": { "Authority": "http://localhost:44385/", diff --git a/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json b/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json index f2457af77..1df50d6b4 100644 --- a/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json +++ b/aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json @@ -22,9 +22,10 @@ "VirtualHost": "Name of your RabbitMQ server VirtualHost" } }, - "RedisCache": { - "RedisPrefix": "Platform_Test_Cache", - "ConnectString": "127.0.0.1" + "Redis": { + "Configuration": "127.0.0.1", + "InstanceName": "LINGYUN.AbpApplication", + "DefaultDatabase": 10 }, "AuthServer": { "Authority": "http://localhost:44385/", diff --git a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs index baffec853..d8b642531 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs +++ b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs @@ -1,10 +1,12 @@ using DotNetCore.CAP; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.IdentityServer; +using LINGYUN.Abp.MultiTenancy.DbFinder; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -17,6 +19,7 @@ using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.Auditing; using Volo.Abp.Autofac; using Volo.Abp.Caching; +using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; @@ -39,6 +42,8 @@ namespace AuthServer.Host typeof(AbpAutofacModule), typeof(AbpCAPEventBusModule), typeof(AbpIdentityAspNetCoreModule), + typeof(AbpDbFinderMultiTenancyModule), + typeof(AbpCachingStackExchangeRedisModule), typeof(AbpIdentityServerSmsValidatorModule), typeof(AbpIdentityServerWeChatValidatorModule), typeof(AbpEntityFrameworkCoreMySQLModule), @@ -88,13 +93,27 @@ namespace AuthServer.Host Configure(options => { + // 最好统一命名,不然某个缓存变动其他应用服务有例外发生 + options.KeyPrefix = "LINGYUN.Abp.Application"; // 滑动过期30天 options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); // 绝对过期60天 - options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddDays(60); options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); }); + Configure(options => + { + var redisConfig = ConfigurationOptions.Parse(options.Configuration); + // 单独一个缓存数据库 + var databaseConfig = configuration.GetSection("Redis:DefaultDatabase"); + if (databaseConfig.Exists()) + { + redisConfig.DefaultDatabase = databaseConfig.Get(); + } + options.ConfigurationOptions = redisConfig; + options.InstanceName = configuration["Redis:InstanceName"]; + }); + Configure(options => { options.Languages.Add(new LanguageInfo("en", "en", "English")); @@ -121,13 +140,6 @@ namespace AuthServer.Host options.IsEnabled = true; }); - context.Services.AddStackExchangeRedisCache(options => - { - options.Configuration = configuration["RedisCache:ConnectString"]; - var instanceName = configuration["RedisCache:RedisPrefix"]; - options.InstanceName = instanceName.IsNullOrEmpty() ? "MessageService_Cache" : instanceName; - }); - if (!hostingEnvironment.IsDevelopment()) { var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); diff --git a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj index fb3b42540..9cfbdb94d 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj +++ b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj @@ -15,12 +15,12 @@ - - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -36,6 +36,7 @@ + diff --git a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs index dcb6e577c..94c4d68ea 100644 --- a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs +++ b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs @@ -6,6 +6,7 @@ using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.FileManagement; using LINGYUN.Abp.Location.Tencent; using LINGYUN.Abp.MessageService; +using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.SettingManagement; using LINGYUN.Abp.TenantManagement; using LINGYUN.ApiGateway; @@ -16,6 +17,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -31,10 +33,10 @@ using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Autofac; using Volo.Abp.Caching; +using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; -using Volo.Abp.Identity.EntityFrameworkCore; using Volo.Abp.Identity.Localization; using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.Localization; @@ -87,6 +89,8 @@ namespace LINGYUN.BackendAdmin typeof(AbpCAPEventBusModule), typeof(AbpAliyunSmsModule), typeof(AbpTencentLocationModule), + typeof(AbpDbFinderMultiTenancyModule), + typeof(AbpCachingStackExchangeRedisModule), typeof(AbpAutofacModule) )] public class BackendAdminHostModule : AbpModule @@ -158,12 +162,27 @@ namespace LINGYUN.BackendAdmin Configure(options => { + // 最好统一命名,不然某个缓存变动其他应用服务有例外发生 + options.KeyPrefix = "LINGYUN.Abp.Application"; // 滑动过期30天 options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); // 绝对过期60天 options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); }); + Configure(options => + { + var redisConfig = ConfigurationOptions.Parse(options.Configuration); + // 单独一个缓存数据库 + var databaseConfig = configuration.GetSection("Redis:DefaultDatabase"); + if (databaseConfig.Exists()) + { + redisConfig.DefaultDatabase = databaseConfig.Get(); + } + options.ConfigurationOptions = redisConfig; + options.InstanceName = configuration["Redis:InstanceName"]; + }); + Configure(options => { options.FileSets.AddEmbedded("LINGYUN.BackendAdmin"); @@ -222,13 +241,6 @@ namespace LINGYUN.BackendAdmin AbpClaimTypes.Email = JwtClaimTypes.Email; }); - context.Services.AddStackExchangeRedisCache(options => - { - options.Configuration = configuration["RedisCache:ConnectString"]; - var instanceName = configuration["RedisCache:RedisPrefix"]; - options.InstanceName = instanceName.IsNullOrEmpty() ? "BackendAdmin_Cache" : instanceName; - }); - if (!hostingEnvironment.IsDevelopment()) { var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); diff --git a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj index b68c8b473..33e5d37b9 100644 --- a/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj +++ b/aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj @@ -26,12 +26,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + @@ -40,6 +39,7 @@ + @@ -75,6 +75,7 @@ + diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs index 6006e0251..5aff1fcda 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs @@ -2,11 +2,13 @@ using DotNetCore.CAP.Messages; using IdentityModel; using LINGYUN.Abp.EventBus.CAP; +using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.ApiGateway.EntityFrameworkCore; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -18,6 +20,8 @@ using System.Text; using Volo.Abp; using Volo.Abp.Autofac; using Volo.Abp.AutoMapper; +using Volo.Abp.Caching; +using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; @@ -42,6 +46,8 @@ namespace LINGYUN.ApiGateway typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpCAPEventBusModule), + typeof(AbpDbFinderMultiTenancyModule), + typeof(AbpCachingStackExchangeRedisModule), typeof(AbpAutofacModule) )] public class ApiGatewayHttpApiHostModule : AbpModule @@ -79,6 +85,29 @@ namespace LINGYUN.ApiGateway options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#"); }); + Configure(options => + { + // 最好统一命名,不然某个缓存变动其他应用服务有例外发生 + options.KeyPrefix = "LINGYUN.Abp.Application"; + // 滑动过期30天 + options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); + // 绝对过期60天 + options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(60); + }); + + Configure(options => + { + var redisConfig = ConfigurationOptions.Parse(options.Configuration); + // 单独一个缓存数据库 + var databaseConfig = configuration.GetSection("Redis:DefaultDatabase"); + if (databaseConfig.Exists()) + { + redisConfig.DefaultDatabase = databaseConfig.Get(); + } + options.ConfigurationOptions = redisConfig; + options.InstanceName = configuration["Redis:InstanceName"]; + }); + // 多租户 Configure(options => { @@ -119,13 +148,6 @@ namespace LINGYUN.ApiGateway AbpClaimTypes.Email = JwtClaimTypes.Email; }); - context.Services.AddStackExchangeRedisCache(options => - { - options.Configuration = configuration["RedisCache:ConnectString"]; - var instanceName = configuration["RedisCache:RedisPrefix"]; - options.InstanceName = instanceName.IsNullOrEmpty() ? "ApiGateway_Cache" : instanceName; - }); - if (!hostingEnvironment.IsDevelopment()) { var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); diff --git a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj index 2c4fb1915..d3c2fdab6 100644 --- a/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj +++ b/aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj @@ -11,15 +11,14 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + @@ -28,6 +27,7 @@ + @@ -40,6 +40,7 @@ + diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj index a70f01c71..11e704e81 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj @@ -19,12 +19,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + @@ -33,6 +32,7 @@ + @@ -53,6 +53,7 @@ + diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs index 8a4b61c99..4e23539e7 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs @@ -10,11 +10,13 @@ using LINGYUN.Abp.IM.SignalR; using LINGYUN.Abp.MessageService.EntityFrameworkCore; using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.MessageService.MultiTenancy; +using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.Notifications.SignalR; using LINGYUN.Abp.Notifications.WeChat.WeApp; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -27,6 +29,7 @@ using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.Autofac; using Volo.Abp.Caching; +using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -56,6 +59,8 @@ namespace LINGYUN.Abp.MessageService typeof(AbpCAPEventBusModule), typeof(AbpBackgroundJobsHangfireModule), typeof(AbpHangfireMySqlStorageModule), + typeof(AbpDbFinderMultiTenancyModule), + typeof(AbpCachingStackExchangeRedisModule), typeof(AbpAutofacModule) )] public class AbpMessageServiceHttpApiHostModule : AbpModule @@ -124,6 +129,29 @@ namespace LINGYUN.Abp.MessageService options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor()); }); + Configure(options => + { + // 最好统一命名,不然某个缓存变动其他应用服务有例外发生 + options.KeyPrefix = "LINGYUN.Abp.Application"; + // 滑动过期30天 + options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); + // 绝对过期60天 + options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); + }); + + Configure(options => + { + var redisConfig = ConfigurationOptions.Parse(options.Configuration); + // 单独一个缓存数据库 + var databaseConfig = configuration.GetSection("Redis:DefaultDatabase"); + if (databaseConfig.Exists()) + { + redisConfig.DefaultDatabase = databaseConfig.Get(); + } + options.ConfigurationOptions = redisConfig; + options.InstanceName = configuration["Redis:InstanceName"]; + }); + // Swagger context.Services.AddSwaggerGen( options => @@ -156,13 +184,6 @@ namespace LINGYUN.Abp.MessageService AbpClaimTypes.Email = JwtClaimTypes.Email; }); - context.Services.AddStackExchangeRedisCache(options => - { - options.Configuration = configuration["RedisCache:ConnectString"]; - var instanceName = configuration["RedisCache:RedisPrefix"]; - options.InstanceName = instanceName.IsNullOrEmpty() ? "MessageService_Cache" : instanceName; - }); - if (!hostingEnvironment.IsDevelopment()) { var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs index f1a4587ff..cf2bf4347 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs @@ -4,6 +4,7 @@ using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.ExceptionHandling; using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.FileManagement; +using LINGYUN.Abp.MultiTenancy.DbFinder; using LINGYUN.Abp.Notifications; using LINGYUN.Platform.EntityFrameworkCore; using LINGYUN.Platform.HttpApi; @@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.Extensions.Caching.StackExchangeRedis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -27,6 +29,7 @@ using Volo.Abp.Autofac; using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring.FileSystem; using Volo.Abp.Caching; +using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -55,6 +58,8 @@ namespace LINGYUN.Platform typeof(AbpEmailingExceptionHandlingModule), typeof(AbpCAPEventBusModule), typeof(AbpBlobStoringFileSystemModule), + typeof(AbpDbFinderMultiTenancyModule), + typeof(AbpCachingStackExchangeRedisModule), typeof(AbpAutofacModule) )] public class AppPlatformHttpApiHostModule : AbpModule @@ -129,12 +134,27 @@ namespace LINGYUN.Platform Configure(options => { + // 最好统一命名,不然某个缓存变动其他应用服务有例外发生 + options.KeyPrefix = "LINGYUN.Abp.Application"; // 滑动过期30天 options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); // 绝对过期60天 options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); }); + Configure(options => + { + var redisConfig = ConfigurationOptions.Parse(options.Configuration); + // 单独一个缓存数据库 + var databaseConfig = configuration.GetSection("Redis:DefaultDatabase"); + if (databaseConfig.Exists()) + { + redisConfig.DefaultDatabase = databaseConfig.Get(); + } + options.ConfigurationOptions = redisConfig; + options.InstanceName = configuration["Redis:InstanceName"]; + }); + Configure(options => { options.FileSets.AddEmbedded("LINGYUN.Platform"); @@ -190,13 +210,6 @@ namespace LINGYUN.Platform AbpClaimTypes.Email = JwtClaimTypes.Email; }); - context.Services.AddStackExchangeRedisCache(options => - { - options.Configuration = configuration["RedisCache:ConnectString"]; - var instanceName = configuration["RedisCache:RedisPrefix"]; - options.InstanceName = instanceName.IsNullOrEmpty() ? "Platform_Cache" : instanceName; - }); - if (!hostingEnvironment.IsDevelopment()) { var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj index ac8e55757..f5881c6cd 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj @@ -21,12 +21,11 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + @@ -35,6 +34,7 @@ + @@ -54,6 +54,7 @@ +