From 2c1543e3eb965099f2c259eec1b24c2f8fd4dbd0 Mon Sep 17 00:00:00 2001
From: cKey <35512826+colinin@users.noreply.github.com>
Date: Sun, 20 Jun 2021 14:56:42 +0800
Subject: [PATCH] add vben admin ui languages maps
---
.../LINGYUN/Platform/Menus/Dto/MenuDto.cs | 64 +-
.../BackendAdminHostModule.cs | 769 +++++++++---------
2 files changed, 422 insertions(+), 411 deletions(-)
diff --git a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/MenuDto.cs b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/MenuDto.cs
index 46e333003..816068c29 100644
--- a/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/MenuDto.cs
+++ b/aspnet-core/modules/platform/LINGYUN.Platform.Application.Contracts/LINGYUN/Platform/Menus/Dto/MenuDto.cs
@@ -1,32 +1,32 @@
-using LINGYUN.Platform.Routes;
-using System;
-using System.Collections.Generic;
-
-namespace LINGYUN.Platform.Menus
-{
- public class MenuDto : RouteDto
- {
- ///
- /// 菜单编号
- ///
- public string Code { get; set; }
- ///
- /// 菜单布局页
- ///
- public string Component { get; set; }
- ///
- /// 所属平台
- ///
- public PlatformType PlatformType { get; set; }
- ///
- /// 父节点
- ///
- public Guid? ParentId { get; set; }
- ///
- /// 所属布局标识
- ///
- public Guid LayoutId { get; set; }
-
- public bool IsPublic { get; set; }
- }
-}
+using LINGYUN.Platform.Routes;
+using System;
+using System.Collections.Generic;
+
+namespace LINGYUN.Platform.Menus
+{
+ public class MenuDto : RouteDto
+ {
+ ///
+ /// 菜单编号
+ ///
+ public string Code { get; set; }
+ ///
+ /// 菜单布局页
+ ///
+ public string Component { get; set; }
+ ///
+ /// 所属平台
+ ///
+ public PlatformType PlatformType { get; set; }
+ ///
+ /// 父节点
+ ///
+ public Guid? ParentId { get; set; }
+ ///
+ /// 所属布局标识
+ ///
+ public Guid LayoutId { get; set; }
+
+ public bool IsPublic { get; set; }
+ }
+}
diff --git a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs
index 0470feb3a..263345da7 100644
--- a/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs
+++ b/aspnet-core/services/admin/LINGYUN.Abp.BackendAdmin.HttpApi.Host/BackendAdminHostModule.cs
@@ -1,379 +1,390 @@
-using DotNetCore.CAP;
-using LINGYUN.Abp.Aliyun.SettingManagement;
-using LINGYUN.Abp.AspNetCore.HttpOverrides;
-using LINGYUN.Abp.Auditing;
-using LINGYUN.Abp.EventBus.CAP;
-using LINGYUN.Abp.ExceptionHandling;
-using LINGYUN.Abp.ExceptionHandling.Emailing;
-using LINGYUN.Abp.FeatureManagement;
-using LINGYUN.Abp.LocalizationManagement;
-using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore;
-using LINGYUN.Abp.MessageService;
-using LINGYUN.Abp.MultiTenancy.DbFinder;
-using LINGYUN.Abp.OssManagement;
-using LINGYUN.Abp.PermissionManagement.Identity;
-using LINGYUN.Abp.SettingManagement;
-using LINGYUN.Abp.Sms.Aliyun;
-using LINGYUN.Abp.TenantManagement;
-using LINGYUN.Abp.WeChat.SettingManagement;
-using LINGYUN.ApiGateway;
-using LINGYUN.Platform;
-using Microsoft.AspNetCore.Authentication.JwtBearer;
-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;
-using Microsoft.OpenApi.Models;
-using StackExchange.Redis;
-using System;
-using System.Text;
-using System.Text.Encodings.Web;
-using System.Text.Unicode;
-using Volo.Abp;
-using Volo.Abp.AspNetCore.Authentication.JwtBearer;
-using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
-using Volo.Abp.AspNetCore.Security.Claims;
-using Volo.Abp.Auditing;
-using Volo.Abp.AuditLogging.EntityFrameworkCore;
-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.Domain.Entities.Events.Distributed;
-using Volo.Abp.EntityFrameworkCore;
-using Volo.Abp.EntityFrameworkCore.MySQL;
-using Volo.Abp.FeatureManagement;
-using Volo.Abp.FeatureManagement.EntityFrameworkCore;
-using Volo.Abp.Identity.EntityFrameworkCore;
-using Volo.Abp.Identity.Localization;
-using Volo.Abp.IdentityServer.EntityFrameworkCore;
-using Volo.Abp.Json;
-using Volo.Abp.Json.SystemTextJson;
-using Volo.Abp.Localization;
-using Volo.Abp.Modularity;
-using Volo.Abp.MultiTenancy;
-using Volo.Abp.PermissionManagement;
-using Volo.Abp.PermissionManagement.EntityFrameworkCore;
-using Volo.Abp.PermissionManagement.HttpApi;
-using Volo.Abp.PermissionManagement.IdentityServer;
-using Volo.Abp.Security.Claims;
-using Volo.Abp.Security.Encryption;
-using Volo.Abp.SettingManagement.EntityFrameworkCore;
-using Volo.Abp.TenantManagement.EntityFrameworkCore;
-using Volo.Abp.Threading;
-using Volo.Abp.VirtualFileSystem;
-
-namespace LINGYUN.Abp.BackendAdmin
-{
- [DependsOn(
- typeof(AbpAspNetCoreMvcUiMultiTenancyModule),
- typeof(PlatformApplicationContractModule),
- typeof(ApiGatewayApplicationContractsModule),
- typeof(AbpOssManagementApplicationContractsModule),
- typeof(AbpMessageServiceApplicationContractsModule),
- typeof(AbpLocalizationManagementApplicationContractsModule),
- typeof(LINGYUN.Abp.Account.AbpAccountApplicationContractsModule),// 引用类似的包主要用于聚合权限管理和设置
- typeof(LINGYUN.Abp.Identity.AbpIdentityApplicationContractsModule),
- typeof(LINGYUN.Abp.IdentityServer.AbpIdentityServerApplicationContractsModule),
- typeof(AbpSettingManagementApplicationModule),
- typeof(AbpSettingManagementHttpApiModule),
- typeof(AbpPermissionManagementApplicationModule),
- typeof(AbpPermissionManagementHttpApiModule),
- typeof(AbpFeatureManagementApplicationModule),
- typeof(AbpFeatureManagementHttpApiModule),
- typeof(AbpFeatureManagementClientModule),
- typeof(AbpAuditingApplicationModule),
- typeof(AbpAuditingHttpApiModule),
- typeof(AbpTenantManagementApplicationModule),
- typeof(AbpTenantManagementHttpApiModule),
- typeof(AbpWeChatSettingManagementModule),// 微信配置管理模块
- typeof(AbpAliyunSettingManagementModule),// 阿里云配置管理模块
- typeof(AbpEntityFrameworkCoreMySQLModule),
- typeof(AbpIdentityEntityFrameworkCoreModule),// 用户角色权限需要引用包
- typeof(AbpIdentityServerEntityFrameworkCoreModule), // 客户端权限需要引用包
- typeof(AbpAuditLoggingEntityFrameworkCoreModule),
- typeof(AbpTenantManagementEntityFrameworkCoreModule),
- typeof(AbpSettingManagementEntityFrameworkCoreModule),
- typeof(AbpPermissionManagementDomainIdentityModule),
- typeof(AbpPermissionManagementDomainIdentityServerModule),
- typeof(AbpPermissionManagementEntityFrameworkCoreModule),
- typeof(AbpFeatureManagementEntityFrameworkCoreModule),
- typeof(AbpLocalizationManagementEntityFrameworkCoreModule),
- typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
- typeof(AbpEmailingExceptionHandlingModule),
- typeof(AbpCAPEventBusModule),
- typeof(AbpAliyunSmsModule),
- typeof(AbpDbFinderMultiTenancyModule),
- typeof(AbpCachingStackExchangeRedisModule),
- typeof(AbpAspNetCoreHttpOverridesModule),
- typeof(AbpAutofacModule)
- )]
- public class BackendAdminHostModule : AbpModule
- {
- public override void PreConfigureServices(ServiceConfigurationContext context)
- {
- var configuration = context.Services.GetConfiguration();
-
- PreConfigure(options =>
- {
- options
- .UseMySql(configuration.GetConnectionString("Default"))
- .UseRabbitMQ(rabbitMQOptions =>
- {
- configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions);
- })
- .UseDashboard();
- });
- }
-
- public override void ConfigureServices(ServiceConfigurationContext context)
- {
- var hostingEnvironment = context.Services.GetHostingEnvironment();
- var configuration = hostingEnvironment.BuildConfiguration();
-
- // 配置Ef
- Configure(options =>
- {
- options.UseMySQL();
- });
-
- // 中文序列化的编码问题
- Configure(options =>
- {
- options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
- });
-
- // 加解密
- Configure(options =>
- {
- var encryptionConfiguration = configuration.GetSection("Encryption");
- if (encryptionConfiguration.Exists())
- {
- options.DefaultPassPhrase = encryptionConfiguration["PassPhrase"] ?? options.DefaultPassPhrase;
- options.DefaultSalt = encryptionConfiguration.GetSection("Salt").Exists()
- ? Encoding.ASCII.GetBytes(encryptionConfiguration["Salt"])
- : options.DefaultSalt;
- options.InitVectorBytes = encryptionConfiguration.GetSection("InitVector").Exists()
- ? Encoding.ASCII.GetBytes(encryptionConfiguration["InitVector"])
- : options.InitVectorBytes;
- }
- });
-
- Configure(options =>
- {
- // Rename IdentityServer.Client.ManagePermissions
- // See https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs
- options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] =
- LINGYUN.Abp.IdentityServer.AbpIdentityServerPermissions.Clients.ManagePermissions;
- });
-
- // 自定义需要处理的异常
- Configure(options =>
- {
- // 加入需要处理的异常类型
- options.Handlers.Add();
- options.Handlers.Add();
- options.Handlers.Add();
- options.Handlers.Add();
- options.Handlers.Add();
- options.Handlers.Add();
- options.Handlers.Add();
- options.Handlers.Add();
- });
- // 自定义需要发送邮件通知的异常类型
- Configure(options =>
- {
- // 是否发送堆栈信息
- options.SendStackTrace = true;
- // 未指定异常接收者的默认接收邮件
- // 请指定自己的邮件地址
- // options.DefaultReceiveEmail = "colin.in@foxmail.com";
- });
-
-
- Configure(options =>
- {
- // 最好统一命名,不然某个缓存变动其他应用服务有例外发生
- options.KeyPrefix = "LINGYUN.Abp.Application";
- // 滑动过期30天
- options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
- // 绝对过期60天
- options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
- });
-
- Configure(options =>
- {
- options.AutoEventSelectors.AddNamespace("Volo.Abp.TenantManagement");
- });
-
- Configure(options =>
- {
- var redisConfig = ConfigurationOptions.Parse(options.Configuration);
- options.ConfigurationOptions = redisConfig;
- options.InstanceName = configuration["Redis:InstanceName"];
- });
-
- Configure(options =>
- {
- options.FileSets.AddEmbedded("LINGYUN.Abp.BackendAdmin");
- });
-
- // 多租户
- Configure(options =>
- {
- options.IsEnabled = true;
- });
-
- var tenantResolveCfg = configuration.GetSection("App:Domains");
- if (tenantResolveCfg.Exists())
- {
- Configure(options =>
- {
- var domains = tenantResolveCfg.Get();
- foreach (var domain in domains)
- {
- options.AddDomainTenantResolver(domain);
- }
- });
- }
-
- Configure(options =>
- {
- options.ApplicationName = "Backend-Admin";
- // 是否启用实体变更记录
- var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged");
- if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get())
- {
- options
- .EntityHistorySelectors
- .AddAllEntities();
- }
- });
-
- // Swagger
- context.Services.AddSwaggerGen(
- options =>
- {
- options.SwaggerDoc("v1", new OpenApiInfo { Title = "BackendAdmin API", Version = "v1" });
- options.DocInclusionPredicate((docName, description) => true);
- options.CustomSchemaIds(type => type.FullName);
- options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
- {
- Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
- Name = "Authorization",
- In = ParameterLocation.Header,
- Scheme = "bearer",
- Type = SecuritySchemeType.Http,
- BearerFormat = "JWT"
- });
- options.AddSecurityRequirement(new OpenApiSecurityRequirement
- {
- {
- new OpenApiSecurityScheme
- {
- Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }
- },
- new string[] { }
- }
- });
- });
-
- // 支持本地化语言类型
- Configure(options =>
- {
- options.Languages.Add(new LanguageInfo("en", "en", "English"));
- options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
-
- options.Resources
- .Get()
- .AddVirtualJson("/Localization");
- options
- .AddLanguagesMapOrUpdate(
- "vue-admin-element-ui",
- new NameValue("zh-Hans", "zh"),
- new NameValue("en", "en"));
- options
- .AddLanguageFilesMapOrUpdate(
- "vue-admin-element-ui",
- new NameValue("zh-Hans", "zh"),
- new NameValue("en", "en"));
-
- options.Resources.AddDynamic();
- });
-
- Configure(options =>
- {
- options.Maps.TryAdd("name", () => AbpClaimTypes.UserName);
- });
-
- context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
- .AddJwtBearer(options =>
- {
- options.Authority = configuration["AuthServer:Authority"];
- options.RequireHttpsMetadata = false;
- options.Audience = configuration["AuthServer:ApiName"];
- });
-
- if (!hostingEnvironment.IsDevelopment())
- {
- var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
- context.Services
- .AddDataProtection()
- .PersistKeysToStackExchangeRedis(redis, "BackendAdmin-Protection-Keys");
- }
- }
-
- public override void OnApplicationInitialization(ApplicationInitializationContext context)
- {
- var app = context.GetApplicationBuilder();
- // http调用链
- app.UseCorrelationId();
- // 虚拟文件系统
- app.UseStaticFiles();
- // 本地化
- app.UseAbpRequestLocalization();
- //路由
- app.UseRouting();
- // 认证
- app.UseAuthentication();
- // jwt
- app.UseJwtTokenMiddleware();
- // 多租户
- app.UseMultiTenancy();
- // Swagger
- app.UseSwagger();
- // Swagger可视化界面
- app.UseSwaggerUI(options =>
- {
- options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support BackendAdmin API");
- });
- // 审计日志
- app.UseAuditing();
- // 处理微信消息
- // app.UseWeChatSignature();
- // 路由
- app.UseConfiguredEndpoints();
-
- // 调试代理连接信息用,上线后注释掉
- app.UseProxyConnectTest();
-
- if (context.GetEnvironment().IsDevelopment())
- {
- SeedData(context);
- }
- }
-
- private void SeedData(ApplicationInitializationContext context)
- {
- AsyncHelper.RunSync(async () =>
- {
- using var scope = context.ServiceProvider.CreateScope();
- await scope.ServiceProvider.GetRequiredService().SeedAsync();
- });
- }
- }
-}
+using DotNetCore.CAP;
+using LINGYUN.Abp.Aliyun.SettingManagement;
+using LINGYUN.Abp.AspNetCore.HttpOverrides;
+using LINGYUN.Abp.Auditing;
+using LINGYUN.Abp.EventBus.CAP;
+using LINGYUN.Abp.ExceptionHandling;
+using LINGYUN.Abp.ExceptionHandling.Emailing;
+using LINGYUN.Abp.FeatureManagement;
+using LINGYUN.Abp.LocalizationManagement;
+using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore;
+using LINGYUN.Abp.MessageService;
+using LINGYUN.Abp.MultiTenancy.DbFinder;
+using LINGYUN.Abp.OssManagement;
+using LINGYUN.Abp.PermissionManagement.Identity;
+using LINGYUN.Abp.SettingManagement;
+using LINGYUN.Abp.Sms.Aliyun;
+using LINGYUN.Abp.TenantManagement;
+using LINGYUN.Abp.WeChat.SettingManagement;
+using LINGYUN.ApiGateway;
+using LINGYUN.Platform;
+using Microsoft.AspNetCore.Authentication.JwtBearer;
+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;
+using Microsoft.OpenApi.Models;
+using StackExchange.Redis;
+using System;
+using System.Text;
+using System.Text.Encodings.Web;
+using System.Text.Unicode;
+using Volo.Abp;
+using Volo.Abp.AspNetCore.Authentication.JwtBearer;
+using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
+using Volo.Abp.AspNetCore.Security.Claims;
+using Volo.Abp.Auditing;
+using Volo.Abp.AuditLogging.EntityFrameworkCore;
+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.Domain.Entities.Events.Distributed;
+using Volo.Abp.EntityFrameworkCore;
+using Volo.Abp.EntityFrameworkCore.MySQL;
+using Volo.Abp.FeatureManagement;
+using Volo.Abp.FeatureManagement.EntityFrameworkCore;
+using Volo.Abp.Identity.EntityFrameworkCore;
+using Volo.Abp.Identity.Localization;
+using Volo.Abp.IdentityServer.EntityFrameworkCore;
+using Volo.Abp.Json;
+using Volo.Abp.Json.SystemTextJson;
+using Volo.Abp.Localization;
+using Volo.Abp.Modularity;
+using Volo.Abp.MultiTenancy;
+using Volo.Abp.PermissionManagement;
+using Volo.Abp.PermissionManagement.EntityFrameworkCore;
+using Volo.Abp.PermissionManagement.HttpApi;
+using Volo.Abp.PermissionManagement.IdentityServer;
+using Volo.Abp.Security.Claims;
+using Volo.Abp.Security.Encryption;
+using Volo.Abp.SettingManagement.EntityFrameworkCore;
+using Volo.Abp.TenantManagement.EntityFrameworkCore;
+using Volo.Abp.Threading;
+using Volo.Abp.VirtualFileSystem;
+
+namespace LINGYUN.Abp.BackendAdmin
+{
+ [DependsOn(
+ typeof(AbpAspNetCoreMvcUiMultiTenancyModule),
+ typeof(PlatformApplicationContractModule),
+ typeof(ApiGatewayApplicationContractsModule),
+ typeof(AbpOssManagementApplicationContractsModule),
+ typeof(AbpMessageServiceApplicationContractsModule),
+ typeof(AbpLocalizationManagementApplicationContractsModule),
+ typeof(LINGYUN.Abp.Account.AbpAccountApplicationContractsModule),// 引用类似的包主要用于聚合权限管理和设置
+ typeof(LINGYUN.Abp.Identity.AbpIdentityApplicationContractsModule),
+ typeof(LINGYUN.Abp.IdentityServer.AbpIdentityServerApplicationContractsModule),
+ typeof(AbpSettingManagementApplicationModule),
+ typeof(AbpSettingManagementHttpApiModule),
+ typeof(AbpPermissionManagementApplicationModule),
+ typeof(AbpPermissionManagementHttpApiModule),
+ typeof(AbpFeatureManagementApplicationModule),
+ typeof(AbpFeatureManagementHttpApiModule),
+ typeof(AbpFeatureManagementClientModule),
+ typeof(AbpAuditingApplicationModule),
+ typeof(AbpAuditingHttpApiModule),
+ typeof(AbpTenantManagementApplicationModule),
+ typeof(AbpTenantManagementHttpApiModule),
+ typeof(AbpWeChatSettingManagementModule),// 微信配置管理模块
+ typeof(AbpAliyunSettingManagementModule),// 阿里云配置管理模块
+ typeof(AbpEntityFrameworkCoreMySQLModule),
+ typeof(AbpIdentityEntityFrameworkCoreModule),// 用户角色权限需要引用包
+ typeof(AbpIdentityServerEntityFrameworkCoreModule), // 客户端权限需要引用包
+ typeof(AbpAuditLoggingEntityFrameworkCoreModule),
+ typeof(AbpTenantManagementEntityFrameworkCoreModule),
+ typeof(AbpSettingManagementEntityFrameworkCoreModule),
+ typeof(AbpPermissionManagementDomainIdentityModule),
+ typeof(AbpPermissionManagementDomainIdentityServerModule),
+ typeof(AbpPermissionManagementEntityFrameworkCoreModule),
+ typeof(AbpFeatureManagementEntityFrameworkCoreModule),
+ typeof(AbpLocalizationManagementEntityFrameworkCoreModule),
+ typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
+ typeof(AbpEmailingExceptionHandlingModule),
+ typeof(AbpCAPEventBusModule),
+ typeof(AbpAliyunSmsModule),
+ typeof(AbpDbFinderMultiTenancyModule),
+ typeof(AbpCachingStackExchangeRedisModule),
+ typeof(AbpAspNetCoreHttpOverridesModule),
+ typeof(AbpAutofacModule)
+ )]
+ public class BackendAdminHostModule : AbpModule
+ {
+ public override void PreConfigureServices(ServiceConfigurationContext context)
+ {
+ var configuration = context.Services.GetConfiguration();
+
+ PreConfigure(options =>
+ {
+ options
+ .UseMySql(configuration.GetConnectionString("Default"))
+ .UseRabbitMQ(rabbitMQOptions =>
+ {
+ configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions);
+ })
+ .UseDashboard();
+ });
+ }
+
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ var hostingEnvironment = context.Services.GetHostingEnvironment();
+ var configuration = hostingEnvironment.BuildConfiguration();
+
+ // 配置Ef
+ Configure(options =>
+ {
+ options.UseMySQL();
+ });
+
+ // 中文序列化的编码问题
+ Configure(options =>
+ {
+ options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
+ });
+
+ // 加解密
+ Configure(options =>
+ {
+ var encryptionConfiguration = configuration.GetSection("Encryption");
+ if (encryptionConfiguration.Exists())
+ {
+ options.DefaultPassPhrase = encryptionConfiguration["PassPhrase"] ?? options.DefaultPassPhrase;
+ options.DefaultSalt = encryptionConfiguration.GetSection("Salt").Exists()
+ ? Encoding.ASCII.GetBytes(encryptionConfiguration["Salt"])
+ : options.DefaultSalt;
+ options.InitVectorBytes = encryptionConfiguration.GetSection("InitVector").Exists()
+ ? Encoding.ASCII.GetBytes(encryptionConfiguration["InitVector"])
+ : options.InitVectorBytes;
+ }
+ });
+
+ Configure(options =>
+ {
+ // Rename IdentityServer.Client.ManagePermissions
+ // See https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs
+ options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] =
+ LINGYUN.Abp.IdentityServer.AbpIdentityServerPermissions.Clients.ManagePermissions;
+ });
+
+ // 自定义需要处理的异常
+ Configure(options =>
+ {
+ // 加入需要处理的异常类型
+ options.Handlers.Add();
+ options.Handlers.Add();
+ options.Handlers.Add();
+ options.Handlers.Add();
+ options.Handlers.Add();
+ options.Handlers.Add();
+ options.Handlers.Add();
+ options.Handlers.Add();
+ });
+ // 自定义需要发送邮件通知的异常类型
+ Configure(options =>
+ {
+ // 是否发送堆栈信息
+ options.SendStackTrace = true;
+ // 未指定异常接收者的默认接收邮件
+ // 请指定自己的邮件地址
+ // options.DefaultReceiveEmail = "colin.in@foxmail.com";
+ });
+
+
+ Configure(options =>
+ {
+ // 最好统一命名,不然某个缓存变动其他应用服务有例外发生
+ options.KeyPrefix = "LINGYUN.Abp.Application";
+ // 滑动过期30天
+ options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
+ // 绝对过期60天
+ options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
+ });
+
+ Configure(options =>
+ {
+ options.AutoEventSelectors.AddNamespace("Volo.Abp.TenantManagement");
+ });
+
+ Configure(options =>
+ {
+ var redisConfig = ConfigurationOptions.Parse(options.Configuration);
+ options.ConfigurationOptions = redisConfig;
+ options.InstanceName = configuration["Redis:InstanceName"];
+ });
+
+ Configure(options =>
+ {
+ options.FileSets.AddEmbedded("LINGYUN.Abp.BackendAdmin");
+ });
+
+ // 多租户
+ Configure(options =>
+ {
+ options.IsEnabled = true;
+ });
+
+ var tenantResolveCfg = configuration.GetSection("App:Domains");
+ if (tenantResolveCfg.Exists())
+ {
+ Configure(options =>
+ {
+ var domains = tenantResolveCfg.Get();
+ foreach (var domain in domains)
+ {
+ options.AddDomainTenantResolver(domain);
+ }
+ });
+ }
+
+ Configure(options =>
+ {
+ options.ApplicationName = "Backend-Admin";
+ // 是否启用实体变更记录
+ var entitiesChangedConfig = configuration.GetSection("App:TrackingEntitiesChanged");
+ if (entitiesChangedConfig.Exists() && entitiesChangedConfig.Get())
+ {
+ options
+ .EntityHistorySelectors
+ .AddAllEntities();
+ }
+ });
+
+ // Swagger
+ context.Services.AddSwaggerGen(
+ options =>
+ {
+ options.SwaggerDoc("v1", new OpenApiInfo { Title = "BackendAdmin API", Version = "v1" });
+ options.DocInclusionPredicate((docName, description) => true);
+ options.CustomSchemaIds(type => type.FullName);
+ options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
+ {
+ Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
+ Name = "Authorization",
+ In = ParameterLocation.Header,
+ Scheme = "bearer",
+ Type = SecuritySchemeType.Http,
+ BearerFormat = "JWT"
+ });
+ options.AddSecurityRequirement(new OpenApiSecurityRequirement
+ {
+ {
+ new OpenApiSecurityScheme
+ {
+ Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }
+ },
+ new string[] { }
+ }
+ });
+ });
+
+ // 支持本地化语言类型
+ Configure(options =>
+ {
+ options.Languages.Add(new LanguageInfo("en", "en", "English"));
+ options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
+
+ options.Resources
+ .Get()
+ .AddVirtualJson("/Localization");
+ options
+ .AddLanguagesMapOrUpdate(
+ "vue-admin-element-ui",
+ new NameValue("zh-Hans", "zh"),
+ new NameValue("en", "en"));
+
+ // vben admin 语言映射
+ options
+ .AddLanguagesMapOrUpdate(
+ "vben-admin-ui",
+ new NameValue("zh_CN", "zh-Hans"));
+
+ options
+ .AddLanguageFilesMapOrUpdate(
+ "vue-admin-element-ui",
+ new NameValue("zh-Hans", "zh"),
+ new NameValue("en", "en"));
+ options
+ .AddLanguageFilesMapOrUpdate(
+ "vben-admin-ui",
+ new NameValue("zh_CN", "zh-Hans"));
+
+ options.Resources.AddDynamic();
+ });
+
+ Configure(options =>
+ {
+ options.Maps.TryAdd("name", () => AbpClaimTypes.UserName);
+ });
+
+ context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
+ .AddJwtBearer(options =>
+ {
+ options.Authority = configuration["AuthServer:Authority"];
+ options.RequireHttpsMetadata = false;
+ options.Audience = configuration["AuthServer:ApiName"];
+ });
+
+ if (!hostingEnvironment.IsDevelopment())
+ {
+ var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
+ context.Services
+ .AddDataProtection()
+ .PersistKeysToStackExchangeRedis(redis, "BackendAdmin-Protection-Keys");
+ }
+ }
+
+ public override void OnApplicationInitialization(ApplicationInitializationContext context)
+ {
+ var app = context.GetApplicationBuilder();
+ // http调用链
+ app.UseCorrelationId();
+ // 虚拟文件系统
+ app.UseStaticFiles();
+ // 本地化
+ app.UseAbpRequestLocalization();
+ //路由
+ app.UseRouting();
+ // 认证
+ app.UseAuthentication();
+ // jwt
+ app.UseJwtTokenMiddleware();
+ // 多租户
+ app.UseMultiTenancy();
+ // Swagger
+ app.UseSwagger();
+ // Swagger可视化界面
+ app.UseSwaggerUI(options =>
+ {
+ options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support BackendAdmin API");
+ });
+ // 审计日志
+ app.UseAuditing();
+ // 处理微信消息
+ // app.UseWeChatSignature();
+ // 路由
+ app.UseConfiguredEndpoints();
+
+ // 调试代理连接信息用,上线后注释掉
+ app.UseProxyConnectTest();
+
+ if (context.GetEnvironment().IsDevelopment())
+ {
+ SeedData(context);
+ }
+ }
+
+ private void SeedData(ApplicationInitializationContext context)
+ {
+ AsyncHelper.RunSync(async () =>
+ {
+ using var scope = context.ServiceProvider.CreateScope();
+ await scope.ServiceProvider.GetRequiredService().SeedAsync();
+ });
+ }
+ }
+}