< 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    {
 3825        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    {
 4647        ArgumentNullException.ThrowIfNull(services);
 4548        ArgumentNullException.ThrowIfNull(configure);
 49
 4450        _ = services.AddOptions<AspNetCoreGovernanceOptions>()
 4451            .Configure(configure)
 4452            .Validate(static options =>
 4453            {
 4454                try
 4455                {
 4456                    options.Validate();
 4457                    return true;
 4458                }
 4459                catch (InvalidOperationException)
 4460                {
 4461                    return false;
 4462                }
 4463            }, "ASP.NET Core integration options must be valid.")
 4464            .ValidateOnStart();
 65
 4466        _ = services.AddOptions<HttpGovernanceActorContextOptions>()
 4467            .Validate(static options =>
 4468            {
 4469                try
 4470                {
 4471                    options.Validate();
 4472                    return true;
 4473                }
 4474                catch (InvalidOperationException)
 4475                {
 4476                    return false;
 4477                }
 4478            }, "HTTP actor context options must be valid.")
 4479            .ValidateOnStart();
 80
 4481        _ = services.AddOptions<GovernanceHttpResultMappingOptions>()
 4482            .Validate(static options =>
 4483            {
 4484                try
 4485                {
 4486                    options.Validate();
 4487                    return true;
 4488                }
 4489                catch (InvalidOperationException)
 4490                {
 4491                    return false;
 4492                }
 4493            }, "HTTP result mapping options must be valid.")
 4494            .ValidateOnStart();
 95
 4496        _ = services.AddOptions<AcknowledgmentChallengeOptions>()
 4497            .Validate(static options =>
 4498            {
 4499                try
 44100                {
 44101                    options.Validate();
 44102                    return true;
 44103                }
 44104                catch (InvalidOperationException)
 44105                {
 44106                    return false;
 44107                }
 44108            }, "Acknowledgment challenge options must be valid.")
 44109            .ValidateOnStart();
 110
 44111        _ = services.AddOptions<EndpointGovernanceOptions>()
 44112            .Validate(static options =>
 44113            {
 44114                try
 44115                {
 44116                    options.Validate();
 44117                    return true;
 44118                }
 44119                catch (InvalidOperationException)
 44120                {
 44121                    return false;
 44122                }
 44123            }, "Endpoint governance options must be valid.")
 44124            .ValidateOnStart();
 125
 44126        _ = services.AddLogging();
 44127        _ = services.AddHttpContextAccessor();
 44128        _ = services.AddScoped<IHttpGovernanceActorContextResolver, HttpContextGovernanceActorContextResolver>();
 44129        _ = services.AddScoped<IHttpGovernanceRequestCorrelationResolver, HttpContextGovernanceRequestCorrelationResolve
 44130        _ = services.AddScoped<IAcknowledgmentChallengeService, DefaultAcknowledgmentChallengeService>();
 44131        _ = services.AddScoped<IEndpointGovernanceService, DefaultEndpointGovernanceService>();
 132
 44133        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}