734b2c91f9
1. 将Hua.Cli.Tests、项目共享库、模块项目等所有项目的TargetFramework从net8.0/net9.0升级到net10.0 2. 完善dotnet-tools.json、模板配置文件,添加必要的构建和发布配置 3. 新增微服务、网关、应用程序的启动脚本和基础配置文件 4. 补充产品管理模块的领域、应用、Web层基础代码和多语言资源
130 lines
4.2 KiB
C#
130 lines
4.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.DataProtection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.OpenApi.Models;
|
|
using Company.Project.Shared;
|
|
using StackExchange.Redis;
|
|
using Volo.Abp;
|
|
using Volo.Abp.AspNetCore.MultiTenancy;
|
|
using Volo.Abp.AspNetCore.Mvc;
|
|
using Volo.Abp.Auditing;
|
|
using Volo.Abp.AuditLogging.EntityFrameworkCore;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.EntityFrameworkCore.SqlServer;
|
|
using Volo.Abp.EventBus.RabbitMq;
|
|
using Volo.Abp.Localization;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
|
using Volo.Abp.TenantManagement.EntityFrameworkCore;
|
|
using Volo.Abp.Threading;
|
|
using Volo.Blogging;
|
|
|
|
namespace Company.Project.BloggingService;
|
|
|
|
[DependsOn(
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpAspNetCoreMvcModule),
|
|
typeof(AbpEventBusRabbitMqModule),
|
|
typeof(AbpEntityFrameworkCoreSqlServerModule),
|
|
typeof(AbpAuditLoggingEntityFrameworkCoreModule),
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
|
typeof(BloggingHttpApiModule),
|
|
typeof(BloggingMongoDbModule),
|
|
typeof(BloggingApplicationModule),
|
|
typeof(AbpAspNetCoreMultiTenancyModule),
|
|
typeof(AbpTenantManagementEntityFrameworkCoreModule)
|
|
)]
|
|
public class BloggingServiceHostModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
Configure<AbpMultiTenancyOptions>(options =>
|
|
{
|
|
options.IsEnabled = ProjectConsts.IsMultiTenancyEnabled;
|
|
});
|
|
|
|
context.Services.AddAuthentication("Bearer")
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.Authority = configuration["AuthServer:Authority"];
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
|
|
options.Audience = configuration["AuthServer:ApiName"];
|
|
});
|
|
|
|
context.Services.AddSwaggerGen(options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Blogging Service API", Version = "v1" });
|
|
options.DocInclusionPredicate((_, _) => true);
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
});
|
|
|
|
Configure<AbpLocalizationOptions>(options =>
|
|
{
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
});
|
|
|
|
Configure<AbpDbContextOptions>(options => options.UseSqlServer());
|
|
|
|
context.Services.AddStackExchangeRedisCache(options =>
|
|
{
|
|
options.Configuration = configuration["Redis:Configuration"];
|
|
});
|
|
|
|
Configure<AbpAuditingOptions>(options =>
|
|
{
|
|
options.IsEnabledForGetRequests = true;
|
|
options.ApplicationName = "BloggingService";
|
|
});
|
|
|
|
var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]);
|
|
context.Services.AddDataProtection()
|
|
.PersistKeysToStackExchangeRedis(redis, "Company.Project-DataProtection-Keys");
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
app.UseCorrelationId();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
|
|
if (ProjectConsts.IsMultiTenancyEnabled)
|
|
{
|
|
app.UseMultiTenancy();
|
|
}
|
|
|
|
app.UseAbpRequestLocalization();
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Blogging Service API");
|
|
});
|
|
app.UseAuditing();
|
|
app.UseConfiguredEndpoints();
|
|
|
|
AsyncHelper.RunSync(async () =>
|
|
{
|
|
using (var scope = context.ServiceProvider.CreateScope())
|
|
{
|
|
await scope.ServiceProvider
|
|
.GetRequiredService<IDataSeeder>()
|
|
.SeedAsync();
|
|
}
|
|
});
|
|
}
|
|
}
|