You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
8.9 KiB
232 lines
8.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Lion.AbpPro.DataDictionaryManagement.EntityFrameworkCore;
|
|
using StackExchange.Redis;
|
|
using Microsoft.OpenApi.Models;
|
|
using Volo.Abp;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy;
|
|
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
|
|
using Volo.Abp.AspNetCore.Serilog;
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.Caching;
|
|
using Volo.Abp.Caching.StackExchangeRedis;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.EntityFrameworkCore.MySQL;
|
|
using Volo.Abp.Localization;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
|
using Volo.Abp.Swashbuckle;
|
|
using Volo.Abp.VirtualFileSystem;
|
|
|
|
namespace Lion.AbpPro.DataDictionaryManagement
|
|
{
|
|
[DependsOn(
|
|
typeof(DataDictionaryManagementApplicationModule),
|
|
typeof(DataDictionaryManagementEntityFrameworkCoreModule),
|
|
typeof(DataDictionaryManagementHttpApiModule),
|
|
typeof(AbpAspNetCoreMvcUiMultiTenancyModule),
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpCachingStackExchangeRedisModule),
|
|
typeof(AbpEntityFrameworkCoreMySQLModule),
|
|
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
|
typeof(AbpAspNetCoreSerilogModule),
|
|
typeof(AbpSwashbuckleModule)
|
|
)]
|
|
public class DataDictionaryManagementHttpApiHostModule : AbpModule
|
|
{
|
|
private const string DefaultCorsPolicyName = "Default";
|
|
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
|
|
// Configure<AbpMultiTenancyOptions>(options =>
|
|
// {
|
|
// options.IsEnabled = MultiTenancyConsts.IsEnabled;
|
|
// });
|
|
|
|
ConfigureSwaggerServices(context);
|
|
ConfigureCache(context);
|
|
ConfigureCors(context);
|
|
ConfigureDB();
|
|
ConfigureLocalization();
|
|
ConfigureVirtualFileSystem(context);
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
var env = context.GetEnvironment();
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseErrorPage();
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseCorrelationId();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseCors(DefaultCorsPolicyName);
|
|
app.UseAuthentication();
|
|
// if (MultiTenancyConsts.IsEnabled)
|
|
// {
|
|
// app.UseMultiTenancy();
|
|
// }
|
|
app.UseAbpRequestLocalization();
|
|
app.UseAuthorization();
|
|
app.UseSwagger();
|
|
app.UseAbpSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API");
|
|
|
|
var configuration = context.GetConfiguration();
|
|
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
|
|
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
|
|
options.OAuthScopes("DataDictionaryManagement");
|
|
});
|
|
app.UseAuditing();
|
|
app.UseAbpSerilogEnrichers();
|
|
app.UseConfiguredEndpoints();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置跨域
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
private void ConfigureCors(ServiceConfigurationContext context)
|
|
{
|
|
var configuration = context.Services.GetConfiguration();
|
|
context.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
{
|
|
builder
|
|
.WithOrigins(
|
|
configuration["App:CorsOrigins"]
|
|
.Split(",", StringSplitOptions.RemoveEmptyEntries)
|
|
.Select(o => o.RemovePostFix("/"))
|
|
.ToArray()
|
|
)
|
|
.WithAbpExposedHeaders()
|
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 配置SwaggerUI
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
|
|
{
|
|
context.Services.AddSwaggerGen(
|
|
options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo {Title = "DataDictionaryManagement API", Version = "v1"});
|
|
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
|
|
#region 添加token
|
|
|
|
options.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, new OpenApiSecurityScheme()
|
|
{
|
|
Description = "请输入Token",
|
|
Name = "Authorization",
|
|
In = ParameterLocation.Header,
|
|
Type = SecuritySchemeType.Http,
|
|
Scheme = JwtBearerDefaults.AuthenticationScheme,
|
|
BearerFormat = "JWT"
|
|
});
|
|
options.AddSecurityRequirement(new OpenApiSecurityRequirement
|
|
{
|
|
{
|
|
new OpenApiSecurityScheme
|
|
{
|
|
Reference = new OpenApiReference
|
|
{
|
|
Type = ReferenceType.SecurityScheme, Id = "Bearer"
|
|
}
|
|
},
|
|
new List<string>()
|
|
}
|
|
});
|
|
|
|
#endregion
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Redis缓存
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
private void ConfigureCache(ServiceConfigurationContext context)
|
|
{
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.GetConfiguration();
|
|
Configure<AbpDistributedCacheOptions>(options => { options.KeyPrefix = "DataDictionaryManagement:"; });
|
|
|
|
if (!hostingEnvironment.IsDevelopment())
|
|
{
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
context.Services
|
|
.AddDataProtection()
|
|
.PersistKeysToStackExchangeRedis(redis, "DataDictionaryManagement-Protection-Keys");
|
|
}
|
|
}
|
|
|
|
private void ConfigureDB()
|
|
{
|
|
Configure<AbpDbContextOptions>(options => { options.UseMySQL(); });
|
|
}
|
|
|
|
/// <summary>
|
|
///配置本地化
|
|
/// </summary>
|
|
private void ConfigureLocalization()
|
|
{
|
|
Configure<AbpLocalizationOptions>(options =>
|
|
{
|
|
options.Languages.Add(new LanguageInfo("cs", "cs", "Čeština"));
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
options.Languages.Add(new LanguageInfo("en-GB", "en-GB", "English (UK)"));
|
|
options.Languages.Add(new LanguageInfo("fr", "fr", "Français"));
|
|
options.Languages.Add(new LanguageInfo("hu", "hu", "Magyar"));
|
|
options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
|
|
options.Languages.Add(new LanguageInfo("ru", "ru", "Русский"));
|
|
options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
|
|
options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
|
|
options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文"));
|
|
});
|
|
}
|
|
/// <summary>
|
|
/// 配置虚拟文件系统
|
|
/// </summary>
|
|
/// <param name="context"></param>
|
|
private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
|
|
{
|
|
Configure<AbpVirtualFileSystemOptions>(options =>
|
|
{
|
|
options.FileSets.AddEmbedded<DataDictionaryManagementHttpApiHostModule>();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|