InternalGatewayHostModule.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using BaseService;
  2. using Microsoft.AspNetCore.Builder;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.OpenApi.Models;
  5. using Ocelot.DependencyInjection;
  6. using Ocelot.Middleware;
  7. using Volo.Abp;
  8. using Volo.Abp.AspNetCore.Serilog;
  9. using Volo.Abp.Autofac;
  10. using Volo.Abp.Identity;
  11. using Volo.Abp.Modularity;
  12. namespace InternalGateway
  13. {
  14. [DependsOn(
  15. typeof(AbpAutofacModule),
  16. typeof(AbpIdentityHttpApiModule),
  17. typeof(BaseServiceHttpApiModule),
  18. typeof(AbpAspNetCoreSerilogModule)
  19. )]
  20. public class InternalGatewayHostModule : AbpModule
  21. {
  22. public override void ConfigureServices(ServiceConfigurationContext context)
  23. {
  24. ConfigureSwaggerServices(context);
  25. context.Services.AddOcelot(context.Services.GetConfiguration());
  26. }
  27. public override void OnApplicationInitialization(ApplicationInitializationContext context)
  28. {
  29. var app = context.GetApplicationBuilder();
  30. app.UseCorrelationId();
  31. app.UseRouting();
  32. app.UseSwagger();
  33. app.UseSwaggerUI(options =>
  34. {
  35. options.SwaggerEndpoint("/swagger/v1/swagger.json", "InternalGateway Service API");
  36. });
  37. app.MapWhen(
  38. ctx => ctx.Request.Path.ToString().StartsWith("/api/abp/") ||
  39. ctx.Request.Path.ToString().StartsWith("/Abp/"),
  40. app2 =>
  41. {
  42. app2.UseRouting();
  43. app2.UseConfiguredEndpoints();
  44. }
  45. );
  46. app.UseOcelot().Wait();
  47. app.UseAbpSerilogEnrichers();
  48. }
  49. private static void ConfigureSwaggerServices(ServiceConfigurationContext context)
  50. {
  51. context.Services.AddSwaggerGen(
  52. options =>
  53. {
  54. options.SwaggerDoc("v1", new OpenApiInfo { Title = "InternalGateway Service API", Version = "v1" });
  55. options.DocInclusionPredicate((docName, description) => true);
  56. });
  57. }
  58. }
  59. }