using System.Collections.Generic; using System.Linq; using System.Security.Claims; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.DependencyInjection; using Ocelot.DependencyInjection; using Ocelot.Middleware; using ProductManagement; using StackExchange.Redis; using Microsoft.OpenApi.Models; using MsDemo.Shared; using Swashbuckle.AspNetCore.Swagger; using Volo.Abp; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.Autofac; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.SqlServer; using Volo.Abp.Identity; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.Security.Claims; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.TenantManagement; using Volo.Blogging; namespace InternalGateway.Host { [DependsOn( typeof(AbpAutofacModule), typeof(AbpIdentityHttpApiModule), typeof(BloggingHttpApiModule), typeof(ProductManagementHttpApiModule), typeof(AbpEntityFrameworkCoreSqlServerModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpTenantManagementHttpApiModule), typeof(AbpAspNetCoreMultiTenancyModule) )] public class InternalGatewayHostModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); Configure(options => { options.IsEnabled = MsDemoConsts.IsMultiTenancyEnabled; }); context.Services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { options.Authority = configuration["AuthServer:Authority"]; options.ApiName = configuration["AuthServer:ApiName"]; options.RequireHttpsMetadata = false; }); context.Services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "Internal Gateway API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); options.CustomSchemaIds(type => type.FullName); }); context.Services.AddOcelot(context.Services.GetConfiguration()); Configure(options => { options.UseSqlServer(); }); context.Services.AddStackExchangeRedisCache(options => { options.Configuration = configuration["Redis:Configuration"]; }); var redis = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]); context.Services.AddDataProtection() .PersistKeysToStackExchangeRedis(redis, "MsDemo-DataProtection-Keys"); } public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); app.UseCorrelationId(); app.UseVirtualFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAbpClaimsMap(); if (MsDemoConsts.IsMultiTenancyEnabled) { app.UseMultiTenancy(); } app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "Internal Gateway API"); }); app.MapWhen( ctx => ctx.Request.Path.ToString().StartsWith("/api/abp/") || ctx.Request.Path.ToString().StartsWith("/Abp/") || ctx.Request.Path.ToString().StartsWith("/Test/"), app2 => { app2.UseRouting(); app2.UseConfiguredEndpoints(); } ); app.UseOcelot().Wait(); } } }