< Summary

Information
Class: ProjectTemplate.Web.Extensions.HealthCheckExtensions
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Extensions/HealthCheckExtensions.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 58
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
AddApplicationHealthChecks(...)100%11100%
MapApplicationHealthChecks(...)100%11100%

File(s)

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

#LineLine coverage
 1using Microsoft.AspNetCore.Diagnostics.HealthChecks;
 2using ProjectTemplate.Web.HealthChecks;
 3
 4namespace ProjectTemplate.Web.Extensions;
 5
 6/// <summary>
 7/// Provides extension methods for registering and mapping application health check endpoints.
 8/// </summary>
 9public static class HealthCheckExtensions
 10{
 11    /// <summary>
 12    /// Registers baseline ASP.NET Core health check services.
 13    /// </summary>
 14    /// <param name="services">The service collection used to register health checks.</param>
 15    /// <returns>The original <see cref="IServiceCollection"/> for chaining.</returns>
 16    public static IServiceCollection AddApplicationHealthChecks(this IServiceCollection services)
 17    {
 11418        services.AddHealthChecks();
 19
 11420        return services;
 21    }
 22
 23    /// <summary>
 24    /// Maps baseline health check endpoints for infrastructure, reverse proxies, and hosting platforms.
 25    /// </summary>
 26    /// <remarks>
 27    /// <c>/health/ready</c> runs only checks tagged <see cref="ApplicationHealthCheckTags.Ready"/>, and
 28    /// <c>/health/audit-integrity</c> runs only checks tagged <see cref="ApplicationHealthCheckTags.Audit"/>. Audit int
 29    /// reported separately so an integrity finding alerts operators without removing every replica from rotation.
 30    /// </remarks>
 31    /// <param name="app">The web application used to map health check endpoints.</param>
 32    /// <returns>The original <see cref="WebApplication"/> for chaining.</returns>
 33    public static WebApplication MapApplicationHealthChecks(this WebApplication app)
 34    {
 9835        app.MapHealthChecks("/health")
 9836            .AllowAnonymous();
 37
 9838        app.MapHealthChecks("/health/ready", new HealthCheckOptions
 9839        {
 9840            Predicate = healthCheck => healthCheck.Tags.Contains(ApplicationHealthCheckTags.Ready)
 9841        })
 9842        .AllowAnonymous();
 43
 9844        app.MapHealthChecks("/health/audit-integrity", new HealthCheckOptions
 9845        {
 9846            Predicate = healthCheck => healthCheck.Tags.Contains(ApplicationHealthCheckTags.Audit)
 9847        })
 9848        .AllowAnonymous();
 49
 9850        app.MapHealthChecks("/health/live", new HealthCheckOptions
 9851        {
 9852            Predicate = _ => false
 9853        })
 9854        .AllowAnonymous();
 55
 9856        return app;
 57    }
 58}