< Summary

Information
Class: AsiBackbone.AspNetCore.DependencyInjection.AspNetCoreGovernanceOptions
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/DependencyInjection/AspNetCoreGovernanceOptions.cs
Line coverage
100%
Covered lines: 14
Uncovered lines: 0
Coverable lines: 14
Total lines: 97
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
get_IncludeEndpointMetadata()100%22100%
set_IncludeEndpointMetadata(...)100%11100%
get_CorrelationIdHeaderName()100%22100%
set_CorrelationIdHeaderName(...)100%11100%
Validate()100%66100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/DependencyInjection/AspNetCoreGovernanceOptions.cs

#LineLine coverage
 1namespace AsiBackbone.AspNetCore.DependencyInjection;
 2
 3/// <summary>
 4/// Provides configuration options for ASP.NET Core host integration.
 5/// </summary>
 6public sealed class AspNetCoreGovernanceOptions
 7{
 8    /// <summary>
 9    /// Gets the default header names checked for correlation identifier propagation.
 10    /// </summary>
 11    public static IReadOnlyList<string> DefaultCorrelationIdHeaderNames { get; } =
 212    [
 213        "X-Correlation-ID",
 214        "X-Request-ID",
 215        "Traceparent",
 216    ];
 17
 18    /// <summary>
 19    /// Gets or sets a value indicating whether HTTP route values may be included by request-context adapters.
 20    /// </summary>
 21    public bool IncludeRouteValues { get; set; } = true;
 22
 23    /// <summary>
 24    /// Gets or sets a value indicating whether endpoint metadata may be inspected by request-context adapters.
 25    /// </summary>
 26    public bool IncludeEndpointMetadata
 27    {
 528        get => IncludeEndpointDisplayName || IncludeRoutePattern;
 29        set
 30        {
 431            IncludeEndpointDisplayName = value;
 432            IncludeRoutePattern = value;
 433        }
 34    }
 35
 36    /// <summary>
 37    /// Gets or sets a value indicating whether the HTTP method may be included as safe audit metadata.
 38    /// </summary>
 39    public bool IncludeRequestMethod { get; set; } = true;
 40
 41    /// <summary>
 42    /// Gets or sets a value indicating whether the HTTP path may be included as safe audit metadata.
 43    /// </summary>
 44    public bool IncludeRequestPath { get; set; }
 45
 46    /// <summary>
 47    /// Gets or sets a value indicating whether endpoint display names may be included as safe audit metadata.
 48    /// </summary>
 49    public bool IncludeEndpointDisplayName { get; set; } = true;
 50
 51    /// <summary>
 52    /// Gets or sets a value indicating whether endpoint route patterns may be included as safe audit metadata.
 53    /// </summary>
 54    public bool IncludeRoutePattern { get; set; } = true;
 55
 56    /// <summary>
 57    /// Gets or sets a value indicating whether the ASP.NET Core trace identifier is used as the correlation identifier
 58    /// when no configured correlation header is present.
 59    /// </summary>
 60    public bool UseHttpContextTraceIdentifierAsCorrelationId { get; set; } = true;
 61
 62    /// <summary>
 63    /// Gets or sets a value indicating whether correlation identifiers supplied through configured HTTP headers are
 64    /// trusted. The default is <see langword="false" />.
 65    /// </summary>
 66    /// <remarks>
 67    /// Enable this only when a trusted ingress removes caller-supplied correlation headers and writes its own values.
 68    /// Enabling it for requests received directly from untrusted callers lets those callers choose audit correlation
 69    /// identifiers.
 70    /// </remarks>
 71    public bool TrustInboundCorrelationIdHeaders { get; set; }
 72
 73    /// <summary>
 74    /// Gets or sets the primary HTTP header name preferred for correlation identifier propagation.
 75    /// </summary>
 76    public string CorrelationIdHeaderName
 77    {
 478        get => CorrelationIdHeaderNames.FirstOrDefault() ?? string.Empty;
 579        set => CorrelationIdHeaderNames = [value];
 80    }
 81
 82    /// <summary>
 83    /// Gets or sets the HTTP header names checked for correlation identifier propagation.
 84    /// </summary>
 85    public IList<string> CorrelationIdHeaderNames { get; set; } = [.. DefaultCorrelationIdHeaderNames];
 86
 87    /// <summary>
 88    /// Validates the options.
 89    /// </summary>
 90    public void Validate()
 91    {
 8192        if (CorrelationIdHeaderNames is null || CorrelationIdHeaderNames.Count == 0 || CorrelationIdHeaderNames.All(stri
 93        {
 694            throw new InvalidOperationException("At least one correlation identifier header name must be configured.");
 95        }
 7596    }
 97}