734b2c91f9
1. 将Hua.Cli.Tests、项目共享库、模块项目等所有项目的TargetFramework从net8.0/net9.0升级到net10.0 2. 完善dotnet-tools.json、模板配置文件,添加必要的构建和发布配置 3. 新增微服务、网关、应用程序的启动脚本和基础配置文件 4. 补充产品管理模块的领域、应用、Web层基础代码和多语言资源
94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using System;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.OpenApi.Models;
|
|
using Company.Project.Shared;
|
|
using ProductManagement;
|
|
using Volo.Abp;
|
|
using Volo.Abp.AspNetCore.Mvc.Client;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.Http.Client.IdentityModel.Web;
|
|
using Volo.Abp.Identity.Web;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.MultiTenancy;
|
|
using Ocelot.DependencyInjection;
|
|
using Ocelot.Middleware;
|
|
|
|
namespace Company.Project.BackendAdminAppGateway;
|
|
|
|
[DependsOn(
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpHttpClientIdentityModelWebModule),
|
|
typeof(AbpIdentityWebModule),
|
|
typeof(AbpAspNetCoreMvcClientModule),
|
|
typeof(ProductManagementHttpApiModule),
|
|
typeof(ProductManagementWebModule)
|
|
)]
|
|
public class BackendAdminAppGatewayHostModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
Configure<AbpMultiTenancyOptions>(options =>
|
|
{
|
|
options.IsEnabled = ProjectConsts.IsMultiTenancyEnabled;
|
|
});
|
|
|
|
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
.AddJwtBearer(options =>
|
|
{
|
|
options.Authority = configuration["AuthServer:Authority"];
|
|
options.Audience = configuration["AuthServer:ApiName"];
|
|
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
|
|
});
|
|
|
|
context.Services.AddSwaggerGen(options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "BackendAdminApp Gateway API", Version = "v1" });
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
});
|
|
|
|
context.Services.AddOcelot(configuration);
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
app.UseCorrelationId();
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAbpClaimsMap();
|
|
|
|
if (ProjectConsts.IsMultiTenancyEnabled)
|
|
{
|
|
app.UseMultiTenancy();
|
|
}
|
|
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "BackendAdminApp Gateway API");
|
|
});
|
|
|
|
app.UseAbpRequestLocalization();
|
|
|
|
app.MapWhen(
|
|
ctx => ctx.Request.Path.ToString().StartsWith("/api/abp/") ||
|
|
ctx.Request.Path.ToString().StartsWith("/Abp/") ||
|
|
ctx.Request.Path.ToString().StartsWith("/api/identity/"),
|
|
app2 =>
|
|
{
|
|
app2.UseRouting();
|
|
app2.UseConfiguredEndpoints();
|
|
}
|
|
);
|
|
|
|
app.UseOcelot().Wait();
|
|
}
|
|
}
|