< Summary

Information
Class: ProjectTemplate.Web.Extensions.PipelineExtensions
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Extensions/PipelineExtensions.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 63
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseApplicationPipeline(...)100%11100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Extensions/PipelineExtensions.cs

#LineLine coverage
 1using ProjectTemplate.Web.Authentication.Extensions;
 2using ProjectTemplate.Web.ErrorHandling;
 3
 4namespace ProjectTemplate.Web.Extensions;
 5
 6/// <summary>
 7/// Provides extension methods to configure the application's middleware pipeline
 8/// with a predefined, order-sensitive sequence suitable for this template.
 9/// </summary>
 10public static class PipelineExtensions
 11{
 12    /// <summary>
 13    /// Configures the middleware pipeline for the specified <see cref="WebApplication"/>.
 14    /// The ordering includes forwarded headers, request logging, exception handling,
 15    /// security headers, HTTPS redirection, static files, routing, rate limiting, and
 16    /// (optionally) authentication/authorization and endpoint mapping.
 17    /// </summary>
 18    /// <param name="app">The <see cref="WebApplication"/> to configure.</param>
 19    /// <returns>The same <see cref="WebApplication"/> instance for chaining.</returns>
 20    public static WebApplication UseApplicationPipeline(this WebApplication app)
 21    {
 22        // Keep this sequence aligned with ADR-0002 and the middleware documentation.
 23        // Move order-sensitive middleware only after reviewing the documented invariants.
 24
 25        // 1. Proxy/load balancer correction must happen early.
 16026        app.UseApplicationForwardedHeaders();
 27
 28        // 2. Structured request logging should see corrected scheme, host, and client IP.
 15429        app.UseApplicationRequestLogging();
 30
 31        // 3. Centralized exception handling.
 15432        app.UseApplicationErrorHandling();
 15433        app.UseProblemDetails();
 34
 35        // 4. Optional security response headers.
 15436        app.UseApplicationSecurityHeaders();
 37
 38        // 5. HTTPS enforcement.
 15439        app.UseHttpsRedirection();
 40
 41        // 6. Static files before routing if using MVC/Razor UI.
 15442        app.UseStaticFiles();
 43
 44        // 7. Routing.
 15445        app.UseRouting();
 46
 47        // 8. CORS, when needed, should be after routing and before auth.
 15448        app.UseCors();
 49
 50        // 9. Rate limiting after routing when endpoint-specific policies are used.
 15451        app.UseRateLimiter();
 52
 53        // 10. Authentication and authorization.
 15454        app.UseApplicationAuthentication();
 14055        app.UseAuthorization();
 56
 57        // 11. Endpoint mapping.
 14058        app.MapControllers();
 13659        app.MapRazorPages();
 60
 13661        return app;
 62    }
 63}