Beispiel #1
0
        public static void UseDefaultApiPipeline(this IApplicationBuilder app, ApiPipelineOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var appInfo     = options.Configuration.GetApplicationInfo();
            var authOptions = options.Configuration.GetAuthOptions();

            if (options.Environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseMigrationsEndPoint();
            }
            else
            {
                app.UseGlobalExceptionHandler();
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRequestCorrelation();
            app.UseCorrelatedLogs();
            app.UseRouting();
            app.UseCorsWithDefaultPolicy();
            app.UseAuthentication();
            app.UseAuthorization();

            options.PostAuthenticationConfigure?.Invoke();

            app.UseUserIdentityLogging();
            app.UseDiagnostics();
            app.UseOpenApiDocumentation(appInfo, u => u.ConfigureAuth(appInfo, authOptions.Authentication));
            app.UseEndpoints(endpoints =>
            {
                options.PreEndPointsConfigure?.Invoke(endpoints);

                endpoints.MapHealthChecks("/health", new HealthCheckOptions
                {
                    Predicate      = _ => true,
                    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
                });
                endpoints.MapControllers();

                if (options.EnableStartPage)
                {
                    options.StartPageConfigure?.Invoke(endpoints, appInfo);
                }

                options.PostEndPointsConfigure?.Invoke(endpoints);
            });

            LogResolvedEnvironment(options.Environment, options.LoggerFactory);
        }
Beispiel #2
0
        public static void UseDefaultApiPipeline(this IApplicationBuilder app,
                                                 IConfiguration configuration,
                                                 IWebHostEnvironment env,
                                                 ILoggerFactory loggerFactory)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (env == null)
            {
                throw new ArgumentNullException(nameof(env));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            var options = new ApiPipelineOptions(configuration, env, loggerFactory);

            app.UseDefaultApiPipeline(options);
        }