< Summary

Information
Class: AsiBackbone.AspNetCore.DependencyInjection.AsiBackboneAspNetCoreServiceCollectionExtensions
Assembly: AsiBackbone.AspNetCore
File(s): /home/runner/work/AsiBackbone/AsiBackbone/src/AsiBackbone.AspNetCore/DependencyInjection/AsiBackboneAspNetCoreServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 115
Uncovered lines: 0
Coverable lines: 115
Total lines: 220
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
AddAsiBackboneAspNetCore(...)100%11100%
AddAsiBackboneAspNetCore(...)100%11100%
AddAsiBackboneGovernanceOutboxDrainWorker(...)100%11100%
AddAsiBackboneGovernanceOutboxDrainWorker(...)100%11100%

File(s)

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

#LineLine coverage
 1using AsiBackbone.AspNetCore.Acknowledgments;
 2using AsiBackbone.AspNetCore.Actors;
 3using AsiBackbone.AspNetCore.Correlation;
 4using AsiBackbone.AspNetCore.Endpoints;
 5using AsiBackbone.AspNetCore.Outbox;
 6using AsiBackbone.AspNetCore.Results;
 7using AsiBackbone.Core.Outbox;
 8using Microsoft.Extensions.DependencyInjection;
 9using Microsoft.Extensions.DependencyInjection.Extensions;
 10
 11namespace AsiBackbone.AspNetCore.DependencyInjection;
 12
 13/// <summary>
 14/// Provides dependency injection registration helpers for ASP.NET Core host integration.
 15/// </summary>
 16public static class AsiBackboneAspNetCoreServiceCollectionExtensions
 17{
 18    /// <summary>
 19    /// Adds ASP.NET Core integration services for AsiBackbone using default options.
 20    /// </summary>
 21    /// <param name="services">The service collection to add services to.</param>
 22    /// <returns>The same service collection so calls can be chained.</returns>
 23    public static IServiceCollection AddAsiBackboneAspNetCore(this IServiceCollection services)
 24    {
 10425        return services.AddAsiBackboneAspNetCore(_ => { });
 26    }
 27
 28    /// <summary>
 29    /// Adds ASP.NET Core integration services for AsiBackbone using configured options.
 30    /// </summary>
 31    /// <param name="services">The service collection to add services to.</param>
 32    /// <param name="configure">The options configuration callback.</param>
 33    /// <returns>The same service collection so calls can be chained.</returns>
 34    /// <exception cref="ArgumentNullException">
 35    /// Thrown when <paramref name="services" /> or <paramref name="configure" /> is <see langword="null" />.
 36    /// </exception>
 37    /// <remarks>
 38    /// Option validation is deferred to the Microsoft.Extensions.Options pipeline.
 39    /// Invalid option values are reported as <see cref="Microsoft.Extensions.Options.OptionsValidationException" />
 40    /// when <see cref="Microsoft.Extensions.Options.IOptions{TOptions}.Value" /> is resolved or during host startup
 41    /// when <c>ValidateOnStart</c> executes.
 42    /// </remarks>
 43    public static IServiceCollection AddAsiBackboneAspNetCore(
 44        this IServiceCollection services,
 45        Action<AspNetCoreGovernanceOptions> configure)
 46    {
 11247        ArgumentNullException.ThrowIfNull(services);
 11148        ArgumentNullException.ThrowIfNull(configure);
 49
 11050        _ = services.AddOptions<AspNetCoreGovernanceOptions>()
 11051            .Configure(configure)
 11052            .Validate(static options =>
 11053            {
 11054                try
 11055                {
 11056                    options.Validate();
 11057                    return true;
 11058                }
 11059                catch (InvalidOperationException)
 11060                {
 11061                    return false;
 11062                }
 11063            }, "ASP.NET Core integration options must be valid.")
 11064            .ValidateOnStart();
 65
 11066        _ = services.AddOptions<HttpGovernanceActorContextOptions>()
 11067            .Validate(static options =>
 11068            {
 11069                try
 11070                {
 11071                    options.Validate();
 11072                    return true;
 11073                }
 11074                catch (InvalidOperationException)
 11075                {
 11076                    return false;
 11077                }
 11078            }, "HTTP actor context options must be valid.")
 11079            .ValidateOnStart();
 80
 11081        _ = services.AddOptions<GovernanceHttpResultMappingOptions>()
 11082            .Validate(static options =>
 11083            {
 11084                try
 11085                {
 11086                    options.Validate();
 11087                    return true;
 11088                }
 11089                catch (InvalidOperationException)
 11090                {
 11091                    return false;
 11092                }
 11093            }, "HTTP result mapping options must be valid.")
 11094            .ValidateOnStart();
 95
 11096        _ = services.AddOptions<AcknowledgmentChallengeOptions>()
 11097            .Validate(static options =>
 11098            {
 11099                try
 110100                {
 110101                    options.Validate();
 110102                    return true;
 110103                }
 110104                catch (InvalidOperationException)
 110105                {
 110106                    return false;
 110107                }
 110108            }, "Acknowledgment challenge options must be valid.")
 110109            .ValidateOnStart();
 110
 110111        _ = services.AddOptions<EndpointGovernanceOptions>()
 110112            .Validate(static options =>
 110113            {
 110114                try
 110115                {
 110116                    options.Validate();
 110117                    return true;
 110118                }
 110119                catch (InvalidOperationException)
 110120                {
 110121                    return false;
 110122                }
 110123            }, "Endpoint governance options must be valid.")
 110124            .ValidateOnStart();
 125
 110126        _ = services.AddLogging();
 110127        _ = services.AddHttpContextAccessor();
 110128        _ = services.AddScoped<IHttpGovernanceActorContextResolver, HttpContextGovernanceActorContextResolver>();
 110129        _ = services.AddScoped<IHttpGovernanceRequestCorrelationResolver, HttpContextGovernanceRequestCorrelationResolve
 110130        _ = services.AddScoped<IAcknowledgmentChallengeService, DefaultAcknowledgmentChallengeService>();
 110131        _ = services.AddScoped<IEndpointGovernanceService, DefaultEndpointGovernanceService>();
 132
 110133        return services;
 134    }
 135
 136    /// <summary>
 137    /// Adds the host-owned outbox drain worker using default scheduling options.
 138    /// </summary>
 139    /// <remarks>
 140    /// The worker is local to the process in which it is registered, so every replica of a horizontally scaled host run
 141    /// its own worker against the same durable outbox. Coordination before provider emission comes from
 142    /// <see cref="GovernanceOutboxOptions.UseClaimLeases" />, which is enabled by default and requires a store
 143    /// implementing <see cref="IGovernanceOutboxClaimStore" />; the drain throws when it is enabled against a
 144    /// store that cannot claim. Disabling it allows two replicas to select and emit the same envelope, so a host that o
 145    /// out should partition work, run the worker on a single role, or rely on provider-side idempotency.
 146    /// Claiming coordinates workers; it does not by itself create an exactly-once delivery guarantee.
 147    /// </remarks>
 148    /// <param name="services">The service collection to add services to.</param>
 149    /// <returns>The same service collection so calls can be chained.</returns>
 150    public static IServiceCollection AddAsiBackboneGovernanceOutboxDrainWorker(this IServiceCollection services)
 151    {
 2152        return services.AddAsiBackboneGovernanceOutboxDrainWorker(_ => { });
 153    }
 154
 155    /// <summary>
 156    /// Adds the host-owned outbox drain worker using configured scheduling options.
 157    /// </summary>
 158    /// <remarks>
 159    /// The worker is local to the process in which it is registered, so every replica of a horizontally scaled host run
 160    /// its own worker against the same durable outbox. Coordination before provider emission comes from
 161    /// <see cref="GovernanceOutboxOptions.UseClaimLeases" />, which is enabled by default and requires a store
 162    /// implementing <see cref="IGovernanceOutboxClaimStore" />; the drain throws when it is enabled against a
 163    /// store that cannot claim. Disabling it allows two replicas to select and emit the same envelope, so a host that o
 164    /// out should partition work, run the worker on a single role, or rely on provider-side idempotency.
 165    /// Claiming coordinates workers; it does not by itself create an exactly-once delivery guarantee.
 166    ///
 167    /// Validation of <paramref name="configure" /> values is deferred to the options pipeline.
 168    /// Invalid values are reported as <see cref="Microsoft.Extensions.Options.OptionsValidationException" />
 169    /// when options are resolved, including hosted-service startup validation through
 170    /// <see cref="Microsoft.Extensions.Options.IOptionsMonitor{TOptions}.CurrentValue" />.
 171    /// </remarks>
 172    /// <param name="services">The service collection to add services to.</param>
 173    /// <param name="configure">The worker options configuration callback.</param>
 174    /// <returns>The same service collection so calls can be chained.</returns>
 175    /// <exception cref="ArgumentNullException">
 176    /// Thrown when <paramref name="services" /> or <paramref name="configure" /> is <see langword="null" />.
 177    /// </exception>
 178    public static IServiceCollection AddAsiBackboneGovernanceOutboxDrainWorker(
 179        this IServiceCollection services,
 180        Action<GovernanceOutboxDrainWorkerOptions> configure)
 181    {
 12182        ArgumentNullException.ThrowIfNull(services);
 12183        ArgumentNullException.ThrowIfNull(configure);
 184
 12185        _ = services.AddOptions<GovernanceOutboxDrainWorkerOptions>()
 12186            .Configure(configure)
 12187            .Validate(static options =>
 12188            {
 12189                try
 12190                {
 12191                    options.Validate();
 12192                    return true;
 12193                }
 12194                catch (InvalidOperationException)
 12195                {
 12196                    return false;
 12197                }
 12198            }, "Governance outbox drain worker options must be valid.");
 199
 12200        _ = services.AddOptions<GovernanceOutboxOptions>()
 12201            .Validate(static options =>
 12202            {
 12203                try
 12204                {
 12205                    options.Validate();
 12206                    return true;
 12207                }
 12208                catch (InvalidOperationException)
 12209                {
 12210                    return false;
 12211                }
 12212            }, "Governance outbox options must be valid.")
 12213            .ValidateOnStart();
 214
 12215        services.TryAddScoped<GovernanceOutboxDrain>();
 12216        _ = services.AddHostedService<GovernanceOutboxDrainHostedService>();
 217
 12218        return services;
 219    }
 220}