public static IHostBuilder PrebuildDefaultApp(this IHostBuilder hostBuilder, Action <HostBuilderContext, LoggerConfiguration> logger) { return(hostBuilder .AddAutofac() .AddSerilog(logger) .AddHealthChecks((context, builder) => builder .AddCheck("Self", () => HealthCheckResult.Healthy(), new List <string> { "Liveness" }) ) .AddHttpMetrics() .AddOpenApiDocumentation( (context, app) => context.Configuration.Bind("Application", app), (context, sso) => context.Configuration.Bind("SingleSignOn", sso)) .AddRequests() .AddRequestValidation() .AddHttpRequestHandler() .AddEventing() .ConfigureContainer <ContainerBuilder>((context, builder) => { }) .ConfigureServices((context, services) => { services.AddControllers().AddApplicationPart(Assembly.GetEntryAssembly()).AddControllersAsServices(); }) .ConfigureWebHostDefaults(builder => builder.Configure((context, app) => { if (context.HostingEnvironment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.AddErrorHandling(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); var appSettings = new ApplicationOptions(); context.Configuration.Bind("Application", appSettings); var ssoSettings = new SingleSignOnOptions(); context.Configuration.Bind("SingleSignOn", ssoSettings); var openApiSettings = new OpenApiDocumentationOptions() { Path = "/swagger" }; app.AddOpenApiDocumentation(appSettings, ssoSettings, openApiSettings); app.AddReadiness(); app.AddLiveness(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapHttpRequestHandler("api"); }); })) ); }
public static IApplicationBuilder AddOpenApiDocumentation(this IApplicationBuilder app, ApplicationOptions appSettings, SingleSignOnOptions ssoSettings, OpenApiDocumentationOptions openApiSettings) { Log.Verbose("Configured OpenAPI on path {documentPath}", openApiSettings.Path); return(app .UseOpenApi(settings => { settings.DocumentName = settings.DocumentName; }) .UseSwaggerUi3(settings => { settings.Path = openApiSettings.Path; settings.OAuth2Client = new OAuth2ClientSettings { AppName = appSettings.Name, ClientId = ssoSettings.ClientId }; settings.OAuth2Client.AdditionalQueryStringParameters.Add("nonce", "123456"); })); }