chore 调整项目结构
This commit is contained in:
		| @ -2,32 +2,34 @@ 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 Microsoft.AspNetCore.Builder; | ||||
| using Microsoft.AspNetCore.Cors; | ||||
| using Microsoft.AspNetCore.Extensions.DependencyInjection; | ||||
| 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 Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite; | ||||
| using Volo.Abp.AspNetCore.Mvc.UI.Theme.LeptonXLite.Bundling; | ||||
| using StackExchange.Redis; | ||||
| using Microsoft.OpenApi.Models; | ||||
| using OpenIddict.Validation.AspNetCore; | ||||
| using Volo.Abp; | ||||
| using Volo.Abp.Account; | ||||
| using Volo.Abp.Account.Web; | ||||
| using Volo.Abp.AspNetCore.MultiTenancy; | ||||
| using Volo.Abp.AspNetCore.Authentication.JwtBearer; | ||||
| using Volo.Abp.AspNetCore.Mvc; | ||||
| using Volo.Abp.AspNetCore.Mvc.UI.Bundling; | ||||
| using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; | ||||
| 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.Modularity; | ||||
| using Volo.Abp.Security.Claims; | ||||
| using Volo.Abp.Swashbuckle; | ||||
| using Volo.Abp.UI.Navigation.Urls; | ||||
| using Volo.Abp.VirtualFileSystem; | ||||
|  | ||||
| namespace KonSoft.Payment; | ||||
| @ -35,76 +37,35 @@ namespace KonSoft.Payment; | ||||
| [DependsOn( | ||||
|     typeof(PaymentHttpApiModule), | ||||
|     typeof(AbpAutofacModule), | ||||
|     typeof(AbpAspNetCoreMultiTenancyModule), | ||||
|     typeof(AbpCachingStackExchangeRedisModule), | ||||
|     typeof(AbpDistributedLockingModule), | ||||
|     typeof(AbpAspNetCoreMvcUiMultiTenancyModule), | ||||
|     typeof(AbpAspNetCoreAuthenticationJwtBearerModule), | ||||
|     typeof(PaymentApplicationModule), | ||||
|     typeof(PaymentEntityFrameworkCoreModule), | ||||
|     typeof(AbpAspNetCoreMvcUiLeptonXLiteThemeModule), | ||||
|     typeof(AbpAccountWebOpenIddictModule), | ||||
|     typeof(AbpAspNetCoreSerilogModule), | ||||
|     typeof(AbpSwashbuckleModule) | ||||
| )] | ||||
| public class PaymentHttpApiHostModule : AbpModule | ||||
| { | ||||
|     public override void PreConfigureServices(ServiceConfigurationContext context) | ||||
|     { | ||||
|         PreConfigure<OpenIddictBuilder>(builder => | ||||
|         { | ||||
|             builder.AddValidation(options => | ||||
|             { | ||||
|                 options.AddAudiences("Payment"); | ||||
|                 options.UseLocalServer(); | ||||
|                 options.UseAspNetCore(); | ||||
|             }); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     public override void ConfigureServices(ServiceConfigurationContext context) | ||||
|     { | ||||
|         var configuration = context.Services.GetConfiguration(); | ||||
|         var hostingEnvironment = context.Services.GetHostingEnvironment(); | ||||
|  | ||||
|         ConfigureAuthentication(context); | ||||
|         ConfigureBundles(); | ||||
|         ConfigureUrls(configuration); | ||||
|         ConfigureConventionalControllers(); | ||||
|         ConfigureAuthentication(context, configuration); | ||||
|         ConfigureCache(configuration); | ||||
|         ConfigureVirtualFileSystem(context); | ||||
|         ConfigureDataProtection(context, configuration, hostingEnvironment); | ||||
|         ConfigureDistributedLocking(context, configuration); | ||||
|         ConfigureCors(context, configuration); | ||||
|         ConfigureSwaggerServices(context, configuration); | ||||
|     } | ||||
|  | ||||
|     private void ConfigureAuthentication(ServiceConfigurationContext context) | ||||
|     private void ConfigureCache(IConfiguration configuration) | ||||
|     { | ||||
|         context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); | ||||
|         context.Services.Configure<AbpClaimsPrincipalFactoryOptions>(options => | ||||
|         { | ||||
|             options.IsDynamicClaimsEnabled = true; | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void ConfigureBundles() | ||||
|     { | ||||
|         Configure<AbpBundlingOptions>(options => | ||||
|         { | ||||
|             options.StyleBundles.Configure( | ||||
|                 LeptonXLiteThemeBundles.Styles.Global, | ||||
|                 bundle => | ||||
|                 { | ||||
|                     bundle.AddFiles("/global-styles.css"); | ||||
|                 } | ||||
|             ); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void ConfigureUrls(IConfiguration configuration) | ||||
|     { | ||||
|         Configure<AppUrlOptions>(options => | ||||
|         { | ||||
|             options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; | ||||
|             options.RedirectAllowedUrls.AddRange(configuration["App:RedirectAllowedUrls"]?.Split(',') ?? Array.Empty<string>()); | ||||
|  | ||||
|             options.Applications["Angular"].RootUrl = configuration["App:ClientUrl"]; | ||||
|             options.Applications["Angular"].Urls[AccountUrlNames.PasswordReset] = "account/reset-password"; | ||||
|         }); | ||||
|         Configure<AbpDistributedCacheOptions>(options => { options.KeyPrefix = "Payment:"; }); | ||||
|     } | ||||
|  | ||||
|     private void ConfigureVirtualFileSystem(ServiceConfigurationContext context) | ||||
| @ -139,6 +100,22 @@ public class PaymentHttpApiHostModule : AbpModule | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration) | ||||
|     { | ||||
|         context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) | ||||
|             .AddAbpJwtBearer(options => | ||||
|             { | ||||
|                 options.Authority = configuration["AuthServer:Authority"]; | ||||
|                 options.RequireHttpsMetadata = configuration.GetValue<bool>("AuthServer:RequireHttpsMetadata"); | ||||
|                 options.Audience = "Payment"; | ||||
|             }); | ||||
|  | ||||
|         context.Services.Configure<AbpClaimsPrincipalFactoryOptions>(options => | ||||
|         { | ||||
|             options.IsDynamicClaimsEnabled = true; | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private static void ConfigureSwaggerServices(ServiceConfigurationContext context, IConfiguration configuration) | ||||
|     { | ||||
|         context.Services.AddAbpSwaggerGenWithOAuth( | ||||
| @ -155,6 +132,30 @@ public class PaymentHttpApiHostModule : AbpModule | ||||
|             }); | ||||
|     } | ||||
|  | ||||
|     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<IDistributedLockProvider>(sp => | ||||
|         { | ||||
|             var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!); | ||||
|             return new RedisDistributedSynchronizationProvider(connection.GetDatabase()); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private void ConfigureCors(ServiceConfigurationContext context, IConfiguration configuration) | ||||
|     { | ||||
|         context.Services.AddCors(options => | ||||
| @ -186,35 +187,29 @@ public class PaymentHttpApiHostModule : AbpModule | ||||
|         } | ||||
|  | ||||
|         app.UseAbpRequestLocalization(); | ||||
|  | ||||
|         if (!env.IsDevelopment()) | ||||
|         { | ||||
|             app.UseErrorPage(); | ||||
|         } | ||||
|  | ||||
|         app.UseCorrelationId(); | ||||
|         app.UseStaticFiles(); | ||||
|         app.UseRouting(); | ||||
|         app.UseCors(); | ||||
|         app.UseAuthentication(); | ||||
|         app.UseAbpOpenIddictValidation(); | ||||
|  | ||||
|         if (MultiTenancyConsts.IsEnabled) | ||||
|         { | ||||
|             app.UseMultiTenancy(); | ||||
|         } | ||||
|  | ||||
|         app.UseUnitOfWork(); | ||||
|         app.UseDynamicClaims(); | ||||
|         app.UseAuthorization(); | ||||
|  | ||||
|         app.UseSwagger(); | ||||
|         app.UseAbpSwaggerUI(c => | ||||
|         app.UseAbpSwaggerUI(options => | ||||
|         { | ||||
|             c.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment API"); | ||||
|             options.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment API"); | ||||
|  | ||||
|             var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); | ||||
|             c.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); | ||||
|             c.OAuthScopes("Payment"); | ||||
|             var configuration = context.GetConfiguration(); | ||||
|             options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); | ||||
|             options.OAuthScopes("Payment"); | ||||
|         }); | ||||
|  | ||||
|         app.UseAuditing(); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user