< Summary

Information
Class: AsiBackbone.AspNetCore.Endpoints.EndpointGovernanceApplicationBuilderExtensions
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/EndpointGovernanceApplicationBuilderExtensions.cs
Line coverage
100%
Covered lines: 5
Uncovered lines: 0
Coverable lines: 5
Total lines: 52
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseAsiBackboneEndpointGovernance(...)100%44100%

File(s)

/home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/Endpoints/EndpointGovernanceApplicationBuilderExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Builder;
 2
 3namespace AsiBackbone.AspNetCore.Endpoints;
 4
 5/// <summary>
 6/// Provides ASP.NET Core application builder extensions for AsiBackbone endpoint governance.
 7/// </summary>
 8public static class EndpointGovernanceApplicationBuilderExtensions
 9{
 10    private const string EndpointRouteBuilderKey = "__EndpointRouteBuilder";
 11
 12    /// <summary>
 13    /// Adds AsiBackbone endpoint governance middleware to the ASP.NET Core pipeline.
 14    /// </summary>
 15    /// <remarks>
 16    /// <para>
 17    /// This middleware governs the <em>selected</em> endpoint, so it must run after endpoint routing has selected one.
 18    /// Placed before routing, every request reaches it with no endpoint, no governance metadata is found, and the
 19    /// request is forwarded ungoverned unless <see cref="EndpointGovernanceOptions.RequireGovernanceMetadata" />
 20    /// is enabled. Register it after <c>UseRouting</c> and after authentication, so an actor context is available.
 21    /// </para>
 22    /// <para>
 23    /// A host that calls <c>UseRouting</c> explicitly can pass <paramref name="requireEndpointRoutingRegistered" /> to
 24    /// turn that ordering requirement into a startup failure. It is off by default because it cannot be checked
 25    /// reliably: a Minimal API host that never calls <c>UseRouting</c> still routes correctly, because
 26    /// <c>WebApplication</c> inserts routing at the front of the pipeline when endpoints are mapped, and in that case
 27    /// the routing marker is legitimately absent when this method runs.
 28    /// </para>
 29    /// </remarks>
 30    /// <param name="app">The application builder.</param>
 31    /// <param name="requireEndpointRoutingRegistered">
 32    /// When <see langword="true" />, throws if endpoint routing has not been registered before this call. Only use this
 33    /// in hosts that call <c>UseRouting</c> explicitly.
 34    /// </param>
 35    /// <returns>The same application builder so calls can be chained.</returns>
 36    /// <exception cref="ArgumentNullException">Thrown when <paramref name="app" /> is <see langword="null" />.</excepti
 37    /// <exception cref="InvalidOperationException">
 38    /// Thrown when <paramref name="requireEndpointRoutingRegistered" /> is <see langword="true" /> and endpoint routing
 39    /// has not been registered before this call.
 40    /// </exception>
 41    public static IApplicationBuilder UseAsiBackboneEndpointGovernance(
 42        this IApplicationBuilder app,
 43        bool requireEndpointRoutingRegistered = false)
 44    {
 545        ArgumentNullException.ThrowIfNull(app);
 46
 447        return requireEndpointRoutingRegistered && !app.Properties.ContainsKey(EndpointRouteBuilderKey)
 448            ? throw new InvalidOperationException(
 449                "AsiBackbone endpoint governance was registered before endpoint routing. Endpoint governance reads the s
 450            : app.UseMiddleware<EndpointGovernanceMiddleware>();
 51    }
 52}