From dbde1486e2a7a035e3527f0abe453376b439c1f3 Mon Sep 17 00:00:00 2001 From: kon1z Date: Sun, 12 Oct 2025 15:40:33 +0800 Subject: [PATCH] =?UTF-8?q?chore=20=E8=B0=83=E6=95=B4nuget=E5=8C=85?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/KonSoft.AuthServer/Dockerfile | 11 ++ .../KonSoft.AuthServer.csproj | 13 +- .../DispatchHttpApiHostModule.cs | 171 ++---------------- .../KonSoft.Dispatch.HttpApi.Host.csproj | 18 +- .../KonSoft.Payment.HttpApi.Host.csproj | 16 +- .../PaymentHttpApiHostModule.cs | 171 ++---------------- .../KonSoft.Report.HttpApi.Host.csproj | 16 +- .../ReportHttpApiHostModule.cs | 171 ++---------------- ...nSoft.TenantManagement.HttpApi.Host.csproj | 16 +- .../TenantManagementHttpApiHostModule.cs | 171 ++---------------- ...onSoft.Shared.Hosting.Microservices.csproj | 3 +- ...KonSoftSharedHostingMicroservivesModule.cs | 8 +- 12 files changed, 85 insertions(+), 700 deletions(-) diff --git a/applications/KonSoft.AuthServer/Dockerfile b/applications/KonSoft.AuthServer/Dockerfile index 260756b..6b3c1e5 100644 --- a/applications/KonSoft.AuthServer/Dockerfile +++ b/applications/KonSoft.AuthServer/Dockerfile @@ -1,23 +1,34 @@ +# 请参阅 https://aka.ms/customizecontainer 以了解如何自定义调试容器,以及 Visual Studio 如何使用此 Dockerfile 生成映像以更快地进行调试。 + +# 此阶段用于在快速模式(默认为调试配置)下从 VS 运行时 FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base USER $APP_UID WORKDIR /app EXPOSE 8080 EXPOSE 8081 + +# 此阶段用于生成服务项目 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["NuGet.Config", "."] COPY ["applications/KonSoft.AuthServer/KonSoft.AuthServer.csproj", "applications/KonSoft.AuthServer/"] +COPY ["shared/KonSoft.Shared.Hosting.Microservices/KonSoft.Shared.Hosting.Microservices.csproj", "shared/KonSoft.Shared.Hosting.Microservices/"] +COPY ["shared/KonSoft.Shared.Hosting.AspNetCore/KonSoft.Shared.Hosting.AspNetCore.csproj", "shared/KonSoft.Shared.Hosting.AspNetCore/"] +COPY ["shared/KonSoft.Shared.Hosting/KonSoft.Shared.Hosting.csproj", "shared/KonSoft.Shared.Hosting/"] +COPY ["shared/KonSoft.Shared.Localization/KonSoft.Shared.Localization.csproj", "shared/KonSoft.Shared.Localization/"] RUN dotnet restore "./applications/KonSoft.AuthServer/KonSoft.AuthServer.csproj" COPY . . WORKDIR "/src/applications/KonSoft.AuthServer" RUN dotnet build "./KonSoft.AuthServer.csproj" -c $BUILD_CONFIGURATION -o /app/build +# 此阶段用于发布要复制到最终阶段的服务项目 FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./KonSoft.AuthServer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false +# 此阶段在生产中使用,或在常规模式下从 VS 运行时使用(在不使用调试配置时为默认值) FROM base AS final WORKDIR /app COPY --from=publish /app/publish . diff --git a/applications/KonSoft.AuthServer/KonSoft.AuthServer.csproj b/applications/KonSoft.AuthServer/KonSoft.AuthServer.csproj index 2343352..0751a60 100644 --- a/applications/KonSoft.AuthServer/KonSoft.AuthServer.csproj +++ b/applications/KonSoft.AuthServer/KonSoft.AuthServer.csproj @@ -39,22 +39,11 @@ - - - - - - - - + - - - - diff --git a/microservices/KonSoft.Dispatch.HttpApi.Host/DispatchHttpApiHostModule.cs b/microservices/KonSoft.Dispatch.HttpApi.Host/DispatchHttpApiHostModule.cs index 6f14937..1a2fcb4 100644 --- a/microservices/KonSoft.Dispatch.HttpApi.Host/DispatchHttpApiHostModule.cs +++ b/microservices/KonSoft.Dispatch.HttpApi.Host/DispatchHttpApiHostModule.cs @@ -1,179 +1,38 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Medallion.Threading; -using Medallion.Threading.Redis; -using Microsoft.AspNetCore.Authentication.JwtBearer; +using KonSoft.Dispatch.EntityFrameworkCore; +using KonSoft.Shared.Hosting.AspNetCore; +using KonSoft.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using KonSoft.Dispatch.EntityFrameworkCore; -using KonSoft.Dispatch.MultiTenancy; -using StackExchange.Redis; -using Microsoft.OpenApi.Models; using Volo.Abp; -using Volo.Abp.AspNetCore.Authentication.JwtBearer; -using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; -using Volo.Abp.AspNetCore.Serilog; -using Volo.Abp.Autofac; -using Volo.Abp.Caching; -using Volo.Abp.Caching.StackExchangeRedis; -using Volo.Abp.DistributedLocking; -using Volo.Abp.Identity; -using Volo.Abp.Localization; +using Volo.Abp.BackgroundJobs; using Volo.Abp.Modularity; -using Volo.Abp.Security.Claims; -using Volo.Abp.Swashbuckle; -using Volo.Abp.VirtualFileSystem; namespace KonSoft.Dispatch; [DependsOn( typeof(DispatchHttpApiModule), - typeof(AbpAutofacModule), - typeof(AbpCachingStackExchangeRedisModule), - typeof(AbpDistributedLockingModule), - typeof(AbpAspNetCoreMvcUiMultiTenancyModule), - typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(DispatchApplicationModule), typeof(DispatchEntityFrameworkCoreModule), - typeof(AbpAspNetCoreSerilogModule), - typeof(AbpSwashbuckleModule) + typeof(KonSoftSharedHostingMicroservicesModule) )] public class DispatchHttpApiHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - var hostingEnvironment = context.Services.GetHostingEnvironment(); - ConfigureConventionalControllers(); - ConfigureAuthentication(context, configuration); - ConfigureCache(configuration); - ConfigureVirtualFileSystem(context); - ConfigureDataProtection(context, configuration, hostingEnvironment); - ConfigureDistributedLocking(context, configuration); - ConfigureCors(context, configuration); - ConfigureSwaggerServices(context, configuration); - } + SwaggerConfigurationHelper.ConfigureWithOidc( + context: context, + authority: configuration["AuthServer:Authority"]!, + scopes: ["DispatchService"], + discoveryEndpoint: configuration["AuthServer:MetadataAddress"], + apiTitle: "Dispatch Service API" + ); - private void ConfigureCache(IConfiguration configuration) - { - Configure(options => { options.KeyPrefix = "Dispatch:"; }); - } - - private void ConfigureVirtualFileSystem(ServiceConfigurationContext context) - { - var hostingEnvironment = context.Services.GetHostingEnvironment(); - - if (hostingEnvironment.IsDevelopment()) - { - Configure(options => - { - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Dispatch.Domain.Shared")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Dispatch.Domain")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Dispatch.Application.Contracts")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Dispatch.Application")); - }); - } - } - - private void ConfigureConventionalControllers() - { - Configure(options => - { - options.ConventionalControllers.Create(typeof(DispatchApplicationModule).Assembly); - }); - } - - private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddAbpJwtBearer(options => - { - options.Authority = configuration["AuthServer:Authority"]; - options.RequireHttpsMetadata = configuration.GetValue("AuthServer:RequireHttpsMetadata"); - options.Audience = "Dispatch"; - }); - - context.Services.Configure(options => - { - options.IsDynamicClaimsEnabled = true; - }); - } - - private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAbpSwaggerGenWithOAuth( - configuration["AuthServer:Authority"]!, - new Dictionary - { - {"Dispatch", "Dispatch API"} - }, - options => - { - options.SwaggerDoc("v1", new OpenApiInfo { Title = "Dispatch API", Version = "v1" }); - options.DocInclusionPredicate((docName, description) => true); - options.CustomSchemaIds(type => type.FullName); - }); - } - - private void ConfigureDataProtection( - ServiceConfigurationContext context, - IConfiguration configuration, - IWebHostEnvironment hostingEnvironment) - { - var dataProtectionBuilder = context.Services.AddDataProtection().SetApplicationName("Dispatch"); - if (!hostingEnvironment.IsDevelopment()) - { - var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - dataProtectionBuilder.PersistKeysToStackExchangeRedis(redis, "Dispatch-Protection-Keys"); - } - } - - private void ConfigureDistributedLocking( - ServiceConfigurationContext context, - IConfiguration configuration) - { - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); - } - - private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddCors(options => - { - options.AddDefaultPolicy(builder => - { - builder - .WithOrigins(configuration["App:CorsOrigins"]? - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() ?? []) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); + // ֻ¼¼ + Configure(options => options.IsJobExecutionEnabled = false); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -193,7 +52,7 @@ public class DispatchHttpApiHostModule : AbpModule app.UseCors(); app.UseAuthentication(); - if (MultiTenancyConsts.IsEnabled) + if (KonSoftConsts.MultiTenancyEnabled) { app.UseMultiTenancy(); } diff --git a/microservices/KonSoft.Dispatch.HttpApi.Host/KonSoft.Dispatch.HttpApi.Host.csproj b/microservices/KonSoft.Dispatch.HttpApi.Host/KonSoft.Dispatch.HttpApi.Host.csproj index b857725..5138231 100644 --- a/microservices/KonSoft.Dispatch.HttpApi.Host/KonSoft.Dispatch.HttpApi.Host.csproj +++ b/microservices/KonSoft.Dispatch.HttpApi.Host/KonSoft.Dispatch.HttpApi.Host.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -8,21 +8,6 @@ KonSoft.Dispatch-4681b4fd-151f-4221-84a4-929d86723e4c - - - - - - - - - - - - - - - @@ -34,6 +19,7 @@ + diff --git a/microservices/KonSoft.Payment.HttpApi.Host/KonSoft.Payment.HttpApi.Host.csproj b/microservices/KonSoft.Payment.HttpApi.Host/KonSoft.Payment.HttpApi.Host.csproj index 66a2a5e..9d824d3 100644 --- a/microservices/KonSoft.Payment.HttpApi.Host/KonSoft.Payment.HttpApi.Host.csproj +++ b/microservices/KonSoft.Payment.HttpApi.Host/KonSoft.Payment.HttpApi.Host.csproj @@ -8,21 +8,6 @@ KonSoft.Payment-4681b4fd-151f-4221-84a4-929d86723e4c - - - - - - - - - - - - - - - @@ -34,6 +19,7 @@ + diff --git a/microservices/KonSoft.Payment.HttpApi.Host/PaymentHttpApiHostModule.cs b/microservices/KonSoft.Payment.HttpApi.Host/PaymentHttpApiHostModule.cs index 69f4001..57bd455 100644 --- a/microservices/KonSoft.Payment.HttpApi.Host/PaymentHttpApiHostModule.cs +++ b/microservices/KonSoft.Payment.HttpApi.Host/PaymentHttpApiHostModule.cs @@ -1,179 +1,38 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Medallion.Threading; -using Medallion.Threading.Redis; -using Microsoft.AspNetCore.Authentication.JwtBearer; +using KonSoft.Payment.EntityFrameworkCore; +using KonSoft.Shared.Hosting.AspNetCore; +using KonSoft.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using KonSoft.Payment.EntityFrameworkCore; -using KonSoft.Payment.MultiTenancy; -using StackExchange.Redis; -using Microsoft.OpenApi.Models; using Volo.Abp; -using Volo.Abp.AspNetCore.Authentication.JwtBearer; -using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; -using Volo.Abp.AspNetCore.Serilog; -using Volo.Abp.Autofac; -using Volo.Abp.Caching; -using Volo.Abp.Caching.StackExchangeRedis; -using Volo.Abp.DistributedLocking; -using Volo.Abp.Identity; -using Volo.Abp.Localization; +using Volo.Abp.BackgroundJobs; using Volo.Abp.Modularity; -using Volo.Abp.Security.Claims; -using Volo.Abp.Swashbuckle; -using Volo.Abp.VirtualFileSystem; namespace KonSoft.Payment; [DependsOn( typeof(PaymentHttpApiModule), - typeof(AbpAutofacModule), - typeof(AbpCachingStackExchangeRedisModule), - typeof(AbpDistributedLockingModule), - typeof(AbpAspNetCoreMvcUiMultiTenancyModule), - typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(PaymentApplicationModule), typeof(PaymentEntityFrameworkCoreModule), - typeof(AbpAspNetCoreSerilogModule), - typeof(AbpSwashbuckleModule) + typeof(KonSoftSharedHostingMicroservicesModule) )] public class PaymentHttpApiHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - var hostingEnvironment = context.Services.GetHostingEnvironment(); - ConfigureConventionalControllers(); - ConfigureAuthentication(context, configuration); - ConfigureCache(configuration); - ConfigureVirtualFileSystem(context); - ConfigureDataProtection(context, configuration, hostingEnvironment); - ConfigureDistributedLocking(context, configuration); - ConfigureCors(context, configuration); - ConfigureSwaggerServices(context, configuration); - } + SwaggerConfigurationHelper.ConfigureWithOidc( + context: context, + authority: configuration["AuthServer:Authority"]!, + scopes: ["PaymentService"], + discoveryEndpoint: configuration["AuthServer:MetadataAddress"], + apiTitle: "Payment Service API" + ); - private void ConfigureCache(IConfiguration configuration) - { - Configure(options => { options.KeyPrefix = "Payment:"; }); - } - - private void ConfigureVirtualFileSystem(ServiceConfigurationContext context) - { - var hostingEnvironment = context.Services.GetHostingEnvironment(); - - if (hostingEnvironment.IsDevelopment()) - { - Configure(options => - { - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Payment.Domain.Shared")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Payment.Domain")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Payment.Application.Contracts")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Payment.Application")); - }); - } - } - - private void ConfigureConventionalControllers() - { - Configure(options => - { - options.ConventionalControllers.Create(typeof(PaymentApplicationModule).Assembly); - }); - } - - private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddAbpJwtBearer(options => - { - options.Authority = configuration["AuthServer:Authority"]; - options.RequireHttpsMetadata = configuration.GetValue("AuthServer:RequireHttpsMetadata"); - options.Audience = "Payment"; - }); - - context.Services.Configure(options => - { - options.IsDynamicClaimsEnabled = true; - }); - } - - private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAbpSwaggerGenWithOAuth( - configuration["AuthServer:Authority"]!, - new Dictionary - { - {"Payment", "Payment API"} - }, - options => - { - options.SwaggerDoc("v1", new OpenApiInfo { Title = "Payment API", Version = "v1" }); - options.DocInclusionPredicate((docName, description) => true); - options.CustomSchemaIds(type => type.FullName); - }); - } - - private void ConfigureDataProtection( - ServiceConfigurationContext context, - IConfiguration configuration, - IWebHostEnvironment hostingEnvironment) - { - var dataProtectionBuilder = context.Services.AddDataProtection().SetApplicationName("Payment"); - if (!hostingEnvironment.IsDevelopment()) - { - var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - dataProtectionBuilder.PersistKeysToStackExchangeRedis(redis, "Payment-Protection-Keys"); - } - } - - private void ConfigureDistributedLocking( - ServiceConfigurationContext context, - IConfiguration configuration) - { - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); - } - - private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddCors(options => - { - options.AddDefaultPolicy(builder => - { - builder - .WithOrigins(configuration["App:CorsOrigins"]? - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() ?? []) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); + // ֻ¼¼ + Configure(options => options.IsJobExecutionEnabled = false); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -193,7 +52,7 @@ public class PaymentHttpApiHostModule : AbpModule app.UseCors(); app.UseAuthentication(); - if (MultiTenancyConsts.IsEnabled) + if (KonSoftConsts.MultiTenancyEnabled) { app.UseMultiTenancy(); } diff --git a/microservices/KonSoft.Report.HttpApi.Host/KonSoft.Report.HttpApi.Host.csproj b/microservices/KonSoft.Report.HttpApi.Host/KonSoft.Report.HttpApi.Host.csproj index e936c86..c273510 100644 --- a/microservices/KonSoft.Report.HttpApi.Host/KonSoft.Report.HttpApi.Host.csproj +++ b/microservices/KonSoft.Report.HttpApi.Host/KonSoft.Report.HttpApi.Host.csproj @@ -8,21 +8,6 @@ KonSoft.Report-4681b4fd-151f-4221-84a4-929d86723e4c - - - - - - - - - - - - - - - @@ -34,6 +19,7 @@ + diff --git a/microservices/KonSoft.Report.HttpApi.Host/ReportHttpApiHostModule.cs b/microservices/KonSoft.Report.HttpApi.Host/ReportHttpApiHostModule.cs index 600f6eb..3d27148 100644 --- a/microservices/KonSoft.Report.HttpApi.Host/ReportHttpApiHostModule.cs +++ b/microservices/KonSoft.Report.HttpApi.Host/ReportHttpApiHostModule.cs @@ -1,179 +1,38 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Medallion.Threading; -using Medallion.Threading.Redis; -using Microsoft.AspNetCore.Authentication.JwtBearer; +using KonSoft.Report.EntityFrameworkCore; +using KonSoft.Shared.Hosting.AspNetCore; +using KonSoft.Shared.Hosting.Microservices; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using KonSoft.Report.EntityFrameworkCore; -using KonSoft.Report.MultiTenancy; -using StackExchange.Redis; -using Microsoft.OpenApi.Models; using Volo.Abp; -using Volo.Abp.AspNetCore.Authentication.JwtBearer; -using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; -using Volo.Abp.AspNetCore.Serilog; -using Volo.Abp.Autofac; -using Volo.Abp.Caching; -using Volo.Abp.Caching.StackExchangeRedis; -using Volo.Abp.DistributedLocking; -using Volo.Abp.Identity; -using Volo.Abp.Localization; +using Volo.Abp.BackgroundJobs; using Volo.Abp.Modularity; -using Volo.Abp.Security.Claims; -using Volo.Abp.Swashbuckle; -using Volo.Abp.VirtualFileSystem; namespace KonSoft.Report; [DependsOn( typeof(ReportHttpApiModule), - typeof(AbpAutofacModule), - typeof(AbpCachingStackExchangeRedisModule), - typeof(AbpDistributedLockingModule), - typeof(AbpAspNetCoreMvcUiMultiTenancyModule), - typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(ReportApplicationModule), typeof(ReportEntityFrameworkCoreModule), - typeof(AbpAspNetCoreSerilogModule), - typeof(AbpSwashbuckleModule) + typeof(KonSoftSharedHostingMicroservicesModule) )] public class ReportHttpApiHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - var hostingEnvironment = context.Services.GetHostingEnvironment(); - ConfigureConventionalControllers(); - ConfigureAuthentication(context, configuration); - ConfigureCache(configuration); - ConfigureVirtualFileSystem(context); - ConfigureDataProtection(context, configuration, hostingEnvironment); - ConfigureDistributedLocking(context, configuration); - ConfigureCors(context, configuration); - ConfigureSwaggerServices(context, configuration); - } + SwaggerConfigurationHelper.ConfigureWithOidc( + context: context, + authority: configuration["AuthServer:Authority"]!, + scopes: ["ReportService"], + discoveryEndpoint: configuration["AuthServer:MetadataAddress"], + apiTitle: "Report Service API" + ); - private void ConfigureCache(IConfiguration configuration) - { - Configure(options => { options.KeyPrefix = "Report:"; }); - } - - private void ConfigureVirtualFileSystem(ServiceConfigurationContext context) - { - var hostingEnvironment = context.Services.GetHostingEnvironment(); - - if (hostingEnvironment.IsDevelopment()) - { - Configure(options => - { - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Report.Domain.Shared")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Report.Domain")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Report.Application.Contracts")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.Report.Application")); - }); - } - } - - private void ConfigureConventionalControllers() - { - Configure(options => - { - options.ConventionalControllers.Create(typeof(ReportApplicationModule).Assembly); - }); - } - - private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddAbpJwtBearer(options => - { - options.Authority = configuration["AuthServer:Authority"]; - options.RequireHttpsMetadata = configuration.GetValue("AuthServer:RequireHttpsMetadata"); - options.Audience = "Report"; - }); - - context.Services.Configure(options => - { - options.IsDynamicClaimsEnabled = true; - }); - } - - private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAbpSwaggerGenWithOAuth( - configuration["AuthServer:Authority"]!, - new Dictionary - { - {"Report", "Report API"} - }, - options => - { - options.SwaggerDoc("v1", new OpenApiInfo { Title = "Report API", Version = "v1" }); - options.DocInclusionPredicate((docName, description) => true); - options.CustomSchemaIds(type => type.FullName); - }); - } - - private void ConfigureDataProtection( - ServiceConfigurationContext context, - IConfiguration configuration, - IWebHostEnvironment hostingEnvironment) - { - var dataProtectionBuilder = context.Services.AddDataProtection().SetApplicationName("Report"); - if (!hostingEnvironment.IsDevelopment()) - { - var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - dataProtectionBuilder.PersistKeysToStackExchangeRedis(redis, "Report-Protection-Keys"); - } - } - - private void ConfigureDistributedLocking( - ServiceConfigurationContext context, - IConfiguration configuration) - { - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); - } - - private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddCors(options => - { - options.AddDefaultPolicy(builder => - { - builder - .WithOrigins(configuration["App:CorsOrigins"]? - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() ?? []) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); + // ֻ¼¼ + Configure(options => options.IsJobExecutionEnabled = false); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -193,7 +52,7 @@ public class ReportHttpApiHostModule : AbpModule app.UseCors(); app.UseAuthentication(); - if (MultiTenancyConsts.IsEnabled) + if (KonSoftConsts.MultiTenancyEnabled) { app.UseMultiTenancy(); } diff --git a/microservices/KonSoft.TenantManagement.HttpApi.Host/KonSoft.TenantManagement.HttpApi.Host.csproj b/microservices/KonSoft.TenantManagement.HttpApi.Host/KonSoft.TenantManagement.HttpApi.Host.csproj index 3f1ccc6..a34913a 100644 --- a/microservices/KonSoft.TenantManagement.HttpApi.Host/KonSoft.TenantManagement.HttpApi.Host.csproj +++ b/microservices/KonSoft.TenantManagement.HttpApi.Host/KonSoft.TenantManagement.HttpApi.Host.csproj @@ -8,21 +8,6 @@ KonSoft.TenantManagement-4681b4fd-151f-4221-84a4-929d86723e4c - - - - - - - - - - - - - - - @@ -34,6 +19,7 @@ + diff --git a/microservices/KonSoft.TenantManagement.HttpApi.Host/TenantManagementHttpApiHostModule.cs b/microservices/KonSoft.TenantManagement.HttpApi.Host/TenantManagementHttpApiHostModule.cs index 669560c..d209b92 100644 --- a/microservices/KonSoft.TenantManagement.HttpApi.Host/TenantManagementHttpApiHostModule.cs +++ b/microservices/KonSoft.TenantManagement.HttpApi.Host/TenantManagementHttpApiHostModule.cs @@ -1,179 +1,38 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Medallion.Threading; -using Medallion.Threading.Redis; -using Microsoft.AspNetCore.Authentication.JwtBearer; +using KonSoft.Shared.Hosting.AspNetCore; +using KonSoft.Shared.Hosting.Microservices; +using KonSoft.TenantManagement.EntityFrameworkCore; using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Cors; -using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using KonSoft.TenantManagement.EntityFrameworkCore; -using KonSoft.TenantManagement.MultiTenancy; -using StackExchange.Redis; -using Microsoft.OpenApi.Models; using Volo.Abp; -using Volo.Abp.AspNetCore.Authentication.JwtBearer; -using Volo.Abp.AspNetCore.Mvc; -using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; -using Volo.Abp.AspNetCore.Serilog; -using Volo.Abp.Autofac; -using Volo.Abp.Caching; -using Volo.Abp.Caching.StackExchangeRedis; -using Volo.Abp.DistributedLocking; -using Volo.Abp.Identity; -using Volo.Abp.Localization; +using Volo.Abp.BackgroundJobs; using Volo.Abp.Modularity; -using Volo.Abp.Security.Claims; -using Volo.Abp.Swashbuckle; -using Volo.Abp.VirtualFileSystem; namespace KonSoft.TenantManagement; [DependsOn( typeof(TenantManagementHttpApiModule), - typeof(AbpAutofacModule), - typeof(AbpCachingStackExchangeRedisModule), - typeof(AbpDistributedLockingModule), - typeof(AbpAspNetCoreMvcUiMultiTenancyModule), - typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(TenantManagementApplicationModule), typeof(TenantManagementEntityFrameworkCoreModule), - typeof(AbpAspNetCoreSerilogModule), - typeof(AbpSwashbuckleModule) + typeof(KonSoftSharedHostingMicroservicesModule) )] public class TenantManagementHttpApiHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); - var hostingEnvironment = context.Services.GetHostingEnvironment(); - ConfigureConventionalControllers(); - ConfigureAuthentication(context, configuration); - ConfigureCache(configuration); - ConfigureVirtualFileSystem(context); - ConfigureDataProtection(context, configuration, hostingEnvironment); - ConfigureDistributedLocking(context, configuration); - ConfigureCors(context, configuration); - ConfigureSwaggerServices(context, configuration); - } + SwaggerConfigurationHelper.ConfigureWithOidc( + context: context, + authority: configuration["AuthServer:Authority"]!, + scopes: ["TenantManagementService"], + discoveryEndpoint: configuration["AuthServer:MetadataAddress"], + apiTitle: "TenantManagement Service API" + ); - private void ConfigureCache(IConfiguration configuration) - { - Configure(options => { options.KeyPrefix = "TenantManagement:"; }); - } - - private void ConfigureVirtualFileSystem(ServiceConfigurationContext context) - { - var hostingEnvironment = context.Services.GetHostingEnvironment(); - - if (hostingEnvironment.IsDevelopment()) - { - Configure(options => - { - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.TenantManagement.Domain.Shared")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.TenantManagement.Domain")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.TenantManagement.Application.Contracts")); - options.FileSets.ReplaceEmbeddedByPhysical( - Path.Combine(hostingEnvironment.ContentRootPath, - $"..{Path.DirectorySeparatorChar}KonSoft.TenantManagement.Application")); - }); - } - } - - private void ConfigureConventionalControllers() - { - Configure(options => - { - options.ConventionalControllers.Create(typeof(TenantManagementApplicationModule).Assembly); - }); - } - - private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) - .AddAbpJwtBearer(options => - { - options.Authority = configuration["AuthServer:Authority"]; - options.RequireHttpsMetadata = configuration.GetValue("AuthServer:RequireHttpsMetadata"); - options.Audience = "TenantManagement"; - }); - - context.Services.Configure(options => - { - options.IsDynamicClaimsEnabled = true; - }); - } - - private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddAbpSwaggerGenWithOAuth( - configuration["AuthServer:Authority"]!, - new Dictionary - { - {"TenantManagement", "TenantManagement API"} - }, - options => - { - options.SwaggerDoc("v1", new OpenApiInfo { Title = "TenantManagement API", Version = "v1" }); - options.DocInclusionPredicate((docName, description) => true); - options.CustomSchemaIds(type => type.FullName); - }); - } - - private void ConfigureDataProtection( - ServiceConfigurationContext context, - IConfiguration configuration, - IWebHostEnvironment hostingEnvironment) - { - var dataProtectionBuilder = context.Services.AddDataProtection().SetApplicationName("TenantManagement"); - if (!hostingEnvironment.IsDevelopment()) - { - var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - dataProtectionBuilder.PersistKeysToStackExchangeRedis(redis, "TenantManagement-Protection-Keys"); - } - } - - private void ConfigureDistributedLocking( - ServiceConfigurationContext context, - IConfiguration configuration) - { - context.Services.AddSingleton(sp => - { - var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); - return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); - }); - } - - private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) - { - context.Services.AddCors(options => - { - options.AddDefaultPolicy(builder => - { - builder - .WithOrigins(configuration["App:CorsOrigins"]? - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .Select(o => o.RemovePostFix("/")) - .ToArray() ?? []) - .WithAbpExposedHeaders() - .SetIsOriginAllowedToAllowWildcardSubdomains() - .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); - }); - }); + // ֻ¼¼ + Configure(options => options.IsJobExecutionEnabled = false); } public override void OnApplicationInitialization(ApplicationInitializationContext context) @@ -193,7 +52,7 @@ public class TenantManagementHttpApiHostModule : AbpModule app.UseCors(); app.UseAuthentication(); - if (MultiTenancyConsts.IsEnabled) + if (KonSoftConsts.MultiTenancyEnabled) { app.UseMultiTenancy(); } diff --git a/shared/KonSoft.Shared.Hosting.Microservices/KonSoft.Shared.Hosting.Microservices.csproj b/shared/KonSoft.Shared.Hosting.Microservices/KonSoft.Shared.Hosting.Microservices.csproj index 1a1f9b2..01bb7b7 100644 --- a/shared/KonSoft.Shared.Hosting.Microservices/KonSoft.Shared.Hosting.Microservices.csproj +++ b/shared/KonSoft.Shared.Hosting.Microservices/KonSoft.Shared.Hosting.Microservices.csproj @@ -11,7 +11,7 @@ - + @@ -22,6 +22,7 @@ + diff --git a/shared/KonSoft.Shared.Hosting.Microservices/KonSoftSharedHostingMicroservivesModule.cs b/shared/KonSoft.Shared.Hosting.Microservices/KonSoftSharedHostingMicroservivesModule.cs index b696d14..fae114e 100644 --- a/shared/KonSoft.Shared.Hosting.Microservices/KonSoftSharedHostingMicroservivesModule.cs +++ b/shared/KonSoft.Shared.Hosting.Microservices/KonSoftSharedHostingMicroservivesModule.cs @@ -2,14 +2,15 @@ using Medallion.Threading; using Medallion.Threading.Redis; using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using StackExchange.Redis; using System; using System.Linq; -using Microsoft.AspNetCore.Cors; using Volo.Abp.AspNetCore.Authentication.JwtBearer; +using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.BackgroundJobs.RabbitMQ; using Volo.Abp.Caching; using Volo.Abp.Caching.StackExchangeRedis; @@ -18,6 +19,7 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EventBus.RabbitMq; using Volo.Abp.Modularity; using Volo.Abp.Security.Claims; +using Volo.Abp.Swashbuckle; namespace KonSoft.Shared.Hosting.Microservices { @@ -28,7 +30,9 @@ namespace KonSoft.Shared.Hosting.Microservices typeof(AbpEventBusRabbitMqModule), typeof(AbpCachingStackExchangeRedisModule), typeof(AbpDistributedLockingModule), - typeof(AbpEntityFrameworkCoreModule) + typeof(AbpAspNetCoreMvcUiMultiTenancyModule), + typeof(AbpEntityFrameworkCoreModule), + typeof(AbpSwashbuckleModule) )] public class KonSoftSharedHostingMicroservicesModule : AbpModule {