Browse Source

add abp-caching-stack-exchange-redis module

pull/64/head
cKey 5 years ago
parent
commit
d98966052b
  1. 7
      aspnet-core/LINGYUN.MicroService.sln
  2. 7
      aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json
  3. 7
      aspnet-core/configuration/admin/LINGYUN.BackendAdminApp.Host/appsettings.Development.json
  4. 7
      aspnet-core/configuration/apigateway/LINGYUN.ApiGateway.HttpApi.Host/appsettings.Development.json
  5. 7
      aspnet-core/configuration/messages/LINGYUN.Abp.MessageService.HttpApi.Host/appsettings.Development.json
  6. 7
      aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json
  7. 28
      aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs
  8. 7
      aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj
  9. 28
      aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/BackendAdminHostModule.cs
  10. 7
      aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj
  11. 36
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs
  12. 13
      aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj
  13. 7
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj
  14. 35
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
  15. 27
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/AppPlatformHttpApiHostModule.cs
  16. 7
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj

7
aspnet-core/LINGYUN.MicroService.sln

@ -213,8 +213,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Identity.Domain
EndProject 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}" 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 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{6FE7E243-2D99-4567-8786-6C9283D608EF}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -680,7 +674,6 @@ Global
{5D0ED1FC-3A7C-4531-9512-832E73AD9555} = {0439B173-F41E-4CE0-A44A-CCB70328F272} {5D0ED1FC-3A7C-4531-9512-832E73AD9555} = {0439B173-F41E-4CE0-A44A-CCB70328F272}
{2BF7FB73-0C62-4ECF-99F0-0583855D2777} = {52B5D4F7-237B-4E0A-A167-68442164F70A} {2BF7FB73-0C62-4ECF-99F0-0583855D2777} = {52B5D4F7-237B-4E0A-A167-68442164F70A}
{6FE7E243-2D99-4567-8786-6C9283D608EF} = {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 EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718} SolutionGuid = {C95FDF91-16F2-4A8B-A4BE-0E62D1B66718}

7
aspnet-core/configuration/account/AuthServer.Host/appsettings.Development.json

@ -48,9 +48,10 @@
"VirtualHost": "multi.service.test" "VirtualHost": "multi.service.test"
} }
}, },
"RedisCache": { "Redis": {
"ConnectString": "127.0.0.1", "Configuration": "127.0.0.1",
"RedisPrefix": "AuthServer" "InstanceName": "LINGYUN.AbpApplication",
"DefaultDatabase": 10
}, },
"AuthServer": { "AuthServer": {
"Authority": "http://localhost:44385/", "Authority": "http://localhost:44385/",

7
aspnet-core/configuration/admin/LINGYUN.BackendAdminApp.Host/appsettings.Development.json

@ -69,9 +69,10 @@
"VirtualHost": "Name of your RabbitMQ server VirtualHost" "VirtualHost": "Name of your RabbitMQ server VirtualHost"
} }
}, },
"RedisCache": { "Redis": {
"RedisPrefix": "Platform_Test_Cache", "Configuration": "127.0.0.1",
"ConnectString": "127.0.0.1" "InstanceName": "LINGYUN.AbpApplication",
"DefaultDatabase": 10
}, },
"AuthServer": { "AuthServer": {
"Authority": "http://localhost:44385/", "Authority": "http://localhost:44385/",

7
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", "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" "AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456"
}, },
"RedisCache": { "Redis": {
"RedisPrefix": "ApiGateway_Test_Cache", "Configuration": "127.0.0.1",
"ConnectString": "127.0.0.1" "InstanceName": "LINGYUN.AbpApplication",
"DefaultDatabase": 10
}, },
"CAP": { "CAP": {
"EventBus": { "EventBus": {

7
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", "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" "AbpPermissionManagement": "Server=127.0.0.1;Database=Platform;User Id=root;Password=123456"
}, },
"RedisCache": { "Redis": {
"RedisPrefix": "Platform_Test_Cache", "Configuration": "127.0.0.1",
"ConnectString": "127.0.0.1" "InstanceName": "LINGYUN.AbpApplication",
"DefaultDatabase": 10
}, },
"AuthServer": { "AuthServer": {
"Authority": "http://localhost:44385/", "Authority": "http://localhost:44385/",

7
aspnet-core/configuration/platform/LINGYUN.Platform.HttpApi.Host/appsettings.Development.json

@ -22,9 +22,10 @@
"VirtualHost": "Name of your RabbitMQ server VirtualHost" "VirtualHost": "Name of your RabbitMQ server VirtualHost"
} }
}, },
"RedisCache": { "Redis": {
"RedisPrefix": "Platform_Test_Cache", "Configuration": "127.0.0.1",
"ConnectString": "127.0.0.1" "InstanceName": "LINGYUN.AbpApplication",
"DefaultDatabase": 10
}, },
"AuthServer": { "AuthServer": {
"Authority": "http://localhost:44385/", "Authority": "http://localhost:44385/",

28
aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs

@ -1,10 +1,12 @@
using DotNetCore.CAP; using DotNetCore.CAP;
using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.IdentityServer; using LINGYUN.Abp.IdentityServer;
using LINGYUN.Abp.MultiTenancy.DbFinder;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -17,6 +19,7 @@ using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.EntityFrameworkCore.MySQL;
@ -39,6 +42,8 @@ namespace AuthServer.Host
typeof(AbpAutofacModule), typeof(AbpAutofacModule),
typeof(AbpCAPEventBusModule), typeof(AbpCAPEventBusModule),
typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityAspNetCoreModule),
typeof(AbpDbFinderMultiTenancyModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpIdentityServerSmsValidatorModule), typeof(AbpIdentityServerSmsValidatorModule),
typeof(AbpIdentityServerWeChatValidatorModule), typeof(AbpIdentityServerWeChatValidatorModule),
typeof(AbpEntityFrameworkCoreMySQLModule), typeof(AbpEntityFrameworkCoreMySQLModule),
@ -88,13 +93,27 @@ namespace AuthServer.Host
Configure<AbpDistributedCacheOptions>(options => Configure<AbpDistributedCacheOptions>(options =>
{ {
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
options.KeyPrefix = "LINGYUN.Abp.Application";
// 滑动过期30天 // 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天 // 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpiration = DateTimeOffset.Now.AddDays(60);
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
}); });
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);
// 单独一个缓存数据库
var databaseConfig = configuration.GetSection("Redis:DefaultDatabase");
if (databaseConfig.Exists())
{
redisConfig.DefaultDatabase = databaseConfig.Get<int>();
}
options.ConfigurationOptions = redisConfig;
options.InstanceName = configuration["Redis:InstanceName"];
});
Configure<AbpLocalizationOptions>(options => Configure<AbpLocalizationOptions>(options =>
{ {
options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("en", "en", "English"));
@ -121,13 +140,6 @@ namespace AuthServer.Host
options.IsEnabled = true; 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()) if (!hostingEnvironment.IsDevelopment())
{ {
var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]);

7
aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj

@ -15,12 +15,12 @@
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" /> <PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.4" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.4" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" /> <PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Identity.AspNetCore" Version="3.0.0" /> <PackageReference Include="Volo.Abp.Identity.AspNetCore" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="3.0.0" />
@ -36,6 +36,7 @@
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.IdentityServer.WeChatValidator\LINGYUN.Abp.IdentityServer.WeChatValidator.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.IdentityServer.WeChatValidator\LINGYUN.Abp.IdentityServer.WeChatValidator.csproj" />
<ProjectReference Include="..\..\..\modules\identityServer\LINGYUN.Abp.IdentityServer.SmsValidator\LINGYUN.Abp.IdentityServer.SmsValidator.csproj" /> <ProjectReference Include="..\..\..\modules\identityServer\LINGYUN.Abp.IdentityServer.SmsValidator\LINGYUN.Abp.IdentityServer.SmsValidator.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy.DbFinder\LINGYUN.Abp.MultiTenancy.DbFinder.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy\LINGYUN.Abp.MultiTenancy.csproj" /> <ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy\LINGYUN.Abp.MultiTenancy.csproj" />
</ItemGroup> </ItemGroup>

28
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.FileManagement;
using LINGYUN.Abp.Location.Tencent; using LINGYUN.Abp.Location.Tencent;
using LINGYUN.Abp.MessageService; using LINGYUN.Abp.MessageService;
using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.Abp.SettingManagement; using LINGYUN.Abp.SettingManagement;
using LINGYUN.Abp.TenantManagement; using LINGYUN.Abp.TenantManagement;
using LINGYUN.ApiGateway; using LINGYUN.ApiGateway;
@ -16,6 +17,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -31,10 +33,10 @@ using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.EntityFrameworkCore.MySQL;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.Identity.Localization; using Volo.Abp.Identity.Localization;
using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.Localization; using Volo.Abp.Localization;
@ -87,6 +89,8 @@ namespace LINGYUN.BackendAdmin
typeof(AbpCAPEventBusModule), typeof(AbpCAPEventBusModule),
typeof(AbpAliyunSmsModule), typeof(AbpAliyunSmsModule),
typeof(AbpTencentLocationModule), typeof(AbpTencentLocationModule),
typeof(AbpDbFinderMultiTenancyModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpAutofacModule) typeof(AbpAutofacModule)
)] )]
public class BackendAdminHostModule : AbpModule public class BackendAdminHostModule : AbpModule
@ -158,12 +162,27 @@ namespace LINGYUN.BackendAdmin
Configure<AbpDistributedCacheOptions>(options => Configure<AbpDistributedCacheOptions>(options =>
{ {
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
options.KeyPrefix = "LINGYUN.Abp.Application";
// 滑动过期30天 // 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天 // 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
}); });
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);
// 单独一个缓存数据库
var databaseConfig = configuration.GetSection("Redis:DefaultDatabase");
if (databaseConfig.Exists())
{
redisConfig.DefaultDatabase = databaseConfig.Get<int>();
}
options.ConfigurationOptions = redisConfig;
options.InstanceName = configuration["Redis:InstanceName"];
});
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {
options.FileSets.AddEmbedded<BackendAdminHostModule>("LINGYUN.BackendAdmin"); options.FileSets.AddEmbedded<BackendAdminHostModule>("LINGYUN.BackendAdmin");
@ -222,13 +241,6 @@ namespace LINGYUN.BackendAdmin
AbpClaimTypes.Email = JwtClaimTypes.Email; 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()) if (!hostingEnvironment.IsDevelopment())
{ {
var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]);

7
aspnet-core/services/admin/LINGYUN.BackendAdminApp.Host/LINGYUN.BackendAdminApp.Host.csproj

@ -26,12 +26,11 @@
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.4" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.4" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" /> <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" /> <PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" />
@ -40,6 +39,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" /> <PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" />
@ -75,6 +75,7 @@
<ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.Application.Contracts\LINGYUN.Platform.Application.Contracts.csproj" /> <ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.Application.Contracts\LINGYUN.Platform.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\settings\LINGYUN.Abp.SettingManagement.Application\LINGYUN.Abp.SettingManagement.Application.csproj" /> <ProjectReference Include="..\..\..\modules\settings\LINGYUN.Abp.SettingManagement.Application\LINGYUN.Abp.SettingManagement.Application.csproj" />
<ProjectReference Include="..\..\..\modules\settings\LINGYUN.Abp.SettingManagement.HttpApi\LINGYUN.Abp.SettingManagement.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\settings\LINGYUN.Abp.SettingManagement.HttpApi\LINGYUN.Abp.SettingManagement.HttpApi.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy.DbFinder\LINGYUN.Abp.MultiTenancy.DbFinder.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.TenantManagement.Application\LINGYUN.Abp.TenantManagement.Application.csproj" /> <ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.TenantManagement.Application\LINGYUN.Abp.TenantManagement.Application.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.TenantManagement.HttpApi\LINGYUN.Abp.TenantManagement.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.TenantManagement.HttpApi\LINGYUN.Abp.TenantManagement.HttpApi.csproj" />
</ItemGroup> </ItemGroup>

36
aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/ApiGatewayHttpApiHostModule.cs

@ -2,11 +2,13 @@
using DotNetCore.CAP.Messages; using DotNetCore.CAP.Messages;
using IdentityModel; using IdentityModel;
using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.EventBus.CAP;
using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.ApiGateway.EntityFrameworkCore; using LINGYUN.ApiGateway.EntityFrameworkCore;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -18,6 +20,8 @@ using System.Text;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.EntityFrameworkCore.MySQL;
@ -42,6 +46,8 @@ namespace LINGYUN.ApiGateway
typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule),
typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule),
typeof(AbpCAPEventBusModule), typeof(AbpCAPEventBusModule),
typeof(AbpDbFinderMultiTenancyModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpAutofacModule) typeof(AbpAutofacModule)
)] )]
public class ApiGatewayHttpApiHostModule : AbpModule public class ApiGatewayHttpApiHostModule : AbpModule
@ -79,6 +85,29 @@ namespace LINGYUN.ApiGateway
options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#"); options.DefaultSalt = Encoding.ASCII.GetBytes("sf&5)s3#");
}); });
Configure<AbpDistributedCacheOptions>(options =>
{
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
options.KeyPrefix = "LINGYUN.Abp.Application";
// 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(60);
});
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);
// 单独一个缓存数据库
var databaseConfig = configuration.GetSection("Redis:DefaultDatabase");
if (databaseConfig.Exists())
{
redisConfig.DefaultDatabase = databaseConfig.Get<int>();
}
options.ConfigurationOptions = redisConfig;
options.InstanceName = configuration["Redis:InstanceName"];
});
// 多租户 // 多租户
Configure<AbpMultiTenancyOptions>(options => Configure<AbpMultiTenancyOptions>(options =>
{ {
@ -119,13 +148,6 @@ namespace LINGYUN.ApiGateway
AbpClaimTypes.Email = JwtClaimTypes.Email; 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()) if (!hostingEnvironment.IsDevelopment())
{ {
var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]);

13
aspnet-core/services/apigateway/LINGYUN.ApiGateway.HttpApi.Host/LINGYUN.ApiGateway.HttpApi.Host.csproj

@ -11,15 +11,14 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.3" /> <PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.3" /> <PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.3" /> <PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.3" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.3" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" /> <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" /> <PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" />
@ -28,6 +27,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" /> <PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.MySQL" Version="3.0.0" /> <PackageReference Include="Volo.Abp.EntityFrameworkCore.MySQL" Version="3.0.0" />
<PackageReference Include="Volo.Abp.TenantManagement.EntityFrameworkCore" Version="3.0.0" /> <PackageReference Include="Volo.Abp.TenantManagement.EntityFrameworkCore" Version="3.0.0" />
@ -40,6 +40,7 @@
<ProjectReference Include="..\..\..\modules\apigateway\LINGYUN.ApiGateway.EntityFrameworkCore\LINGYUN.ApiGateway.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\modules\apigateway\LINGYUN.ApiGateway.EntityFrameworkCore\LINGYUN.ApiGateway.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\modules\apigateway\LINGYUN.ApiGateway.HttpApi\LINGYUN.ApiGateway.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\apigateway\LINGYUN.ApiGateway.HttpApi\LINGYUN.ApiGateway.HttpApi.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" /> <ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.EventBus.CAP\LINGYUN.Abp.EventBus.CAP.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy.DbFinder\LINGYUN.Abp.MultiTenancy.DbFinder.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

7
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj

@ -19,12 +19,11 @@
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.4" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.4" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" /> <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" /> <PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" />
@ -33,6 +32,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" /> <PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" />
@ -53,6 +53,7 @@
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.Application\LINGYUN.Abp.MessageService.Application.csproj" /> <ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.Application\LINGYUN.Abp.MessageService.Application.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.EntityFrameworkCore\LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.EntityFrameworkCore\LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.HttpApi\LINGYUN.Abp.MessageService.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.HttpApi\LINGYUN.Abp.MessageService.HttpApi.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy.DbFinder\LINGYUN.Abp.MultiTenancy.DbFinder.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy\LINGYUN.Abp.MultiTenancy.csproj" /> <ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy\LINGYUN.Abp.MultiTenancy.csproj" />
</ItemGroup> </ItemGroup>

35
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.EntityFrameworkCore;
using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.MessageService.Localization;
using LINGYUN.Abp.MessageService.MultiTenancy; using LINGYUN.Abp.MessageService.MultiTenancy;
using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.Abp.Notifications.SignalR; using LINGYUN.Abp.Notifications.SignalR;
using LINGYUN.Abp.Notifications.WeChat.WeApp; using LINGYUN.Abp.Notifications.WeChat.WeApp;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -27,6 +29,7 @@ using Volo.Abp.AspNetCore.Authentication.JwtBearer;
using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Autofac; using Volo.Abp.Autofac;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -56,6 +59,8 @@ namespace LINGYUN.Abp.MessageService
typeof(AbpCAPEventBusModule), typeof(AbpCAPEventBusModule),
typeof(AbpBackgroundJobsHangfireModule), typeof(AbpBackgroundJobsHangfireModule),
typeof(AbpHangfireMySqlStorageModule), typeof(AbpHangfireMySqlStorageModule),
typeof(AbpDbFinderMultiTenancyModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpAutofacModule) typeof(AbpAutofacModule)
)] )]
public class AbpMessageServiceHttpApiHostModule : AbpModule public class AbpMessageServiceHttpApiHostModule : AbpModule
@ -124,6 +129,29 @@ namespace LINGYUN.Abp.MessageService
options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor()); options.TenantResolvers.Insert(0, new AuthorizationTenantResolveContributor());
}); });
Configure<AbpDistributedCacheOptions>(options =>
{
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
options.KeyPrefix = "LINGYUN.Abp.Application";
// 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
});
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);
// 单独一个缓存数据库
var databaseConfig = configuration.GetSection("Redis:DefaultDatabase");
if (databaseConfig.Exists())
{
redisConfig.DefaultDatabase = databaseConfig.Get<int>();
}
options.ConfigurationOptions = redisConfig;
options.InstanceName = configuration["Redis:InstanceName"];
});
// Swagger // Swagger
context.Services.AddSwaggerGen( context.Services.AddSwaggerGen(
options => options =>
@ -156,13 +184,6 @@ namespace LINGYUN.Abp.MessageService
AbpClaimTypes.Email = JwtClaimTypes.Email; 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()) if (!hostingEnvironment.IsDevelopment())
{ {
var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]);

27
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;
using LINGYUN.Abp.ExceptionHandling.Emailing; using LINGYUN.Abp.ExceptionHandling.Emailing;
using LINGYUN.Abp.FileManagement; using LINGYUN.Abp.FileManagement;
using LINGYUN.Abp.MultiTenancy.DbFinder;
using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications;
using LINGYUN.Platform.EntityFrameworkCore; using LINGYUN.Platform.EntityFrameworkCore;
using LINGYUN.Platform.HttpApi; using LINGYUN.Platform.HttpApi;
@ -12,6 +13,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Caching.StackExchangeRedis;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@ -27,6 +29,7 @@ using Volo.Abp.Autofac;
using Volo.Abp.BlobStoring; using Volo.Abp.BlobStoring;
using Volo.Abp.BlobStoring.FileSystem; using Volo.Abp.BlobStoring.FileSystem;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Localization; using Volo.Abp.Localization;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
@ -55,6 +58,8 @@ namespace LINGYUN.Platform
typeof(AbpEmailingExceptionHandlingModule), typeof(AbpEmailingExceptionHandlingModule),
typeof(AbpCAPEventBusModule), typeof(AbpCAPEventBusModule),
typeof(AbpBlobStoringFileSystemModule), typeof(AbpBlobStoringFileSystemModule),
typeof(AbpDbFinderMultiTenancyModule),
typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpAutofacModule) typeof(AbpAutofacModule)
)] )]
public class AppPlatformHttpApiHostModule : AbpModule public class AppPlatformHttpApiHostModule : AbpModule
@ -129,12 +134,27 @@ namespace LINGYUN.Platform
Configure<AbpDistributedCacheOptions>(options => Configure<AbpDistributedCacheOptions>(options =>
{ {
// 最好统一命名,不然某个缓存变动其他应用服务有例外发生
options.KeyPrefix = "LINGYUN.Abp.Application";
// 滑动过期30天 // 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天 // 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
}); });
Configure<RedisCacheOptions>(options =>
{
var redisConfig = ConfigurationOptions.Parse(options.Configuration);
// 单独一个缓存数据库
var databaseConfig = configuration.GetSection("Redis:DefaultDatabase");
if (databaseConfig.Exists())
{
redisConfig.DefaultDatabase = databaseConfig.Get<int>();
}
options.ConfigurationOptions = redisConfig;
options.InstanceName = configuration["Redis:InstanceName"];
});
Configure<AbpVirtualFileSystemOptions>(options => Configure<AbpVirtualFileSystemOptions>(options =>
{ {
options.FileSets.AddEmbedded<AppPlatformHttpApiHostModule>("LINGYUN.Platform"); options.FileSets.AddEmbedded<AppPlatformHttpApiHostModule>("LINGYUN.Platform");
@ -190,13 +210,6 @@ namespace LINGYUN.Platform
AbpClaimTypes.Email = JwtClaimTypes.Email; 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()) if (!hostingEnvironment.IsDevelopment())
{ {
var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]); var redis = ConnectionMultiplexer.Connect(configuration["RedisCache:ConnectString"]);

7
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj

@ -21,12 +21,11 @@
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" /> <PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="3.1.4" /> <PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.StackExchangeRedis" Version="3.1.4" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" /> <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" /> <PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" /> <PackageReference Include="Serilog.Enrichers.Assembly" Version="2.0.0" />
@ -35,6 +34,7 @@
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" /> <PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="3.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.0" />
<PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" /> <PackageReference Include="Volo.Abp.Autofac" Version="3.0.0" />
@ -54,6 +54,7 @@
<ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.Application\LINGYUN.Platform.Application.csproj" /> <ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.Application\LINGYUN.Platform.Application.csproj" />
<ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.EntityFrameworkCore\LINGYUN.Platform.EntityFrameworkCore.csproj" /> <ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.EntityFrameworkCore\LINGYUN.Platform.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.HttpApi\LINGYUN.Platform.HttpApi.csproj" /> <ProjectReference Include="..\..\..\modules\platform\LINGYUN.Platform.HttpApi\LINGYUN.Platform.HttpApi.csproj" />
<ProjectReference Include="..\..\..\modules\tenants\LINGYUN.Abp.MultiTenancy.DbFinder\LINGYUN.Abp.MultiTenancy.DbFinder.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Loading…
Cancel
Save