< 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
93%
Covered lines: 101
Uncovered lines: 7
Coverable lines: 108
Total lines: 185
Line coverage: 93.5%
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%1195.18%
AddAsiBackboneGovernanceOutboxDrainWorker(...)100%210%
AddAsiBackboneGovernanceOutboxDrainWorker(...)100%1191.3%

File(s)

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

#LineLine coverage
 1using AsiBackbone.AspNetCore.Actors;
 2using AsiBackbone.AspNetCore.Correlation;
 3using AsiBackbone.AspNetCore.Endpoints;
 4using AsiBackbone.AspNetCore.Handshakes;
 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    {
 6925        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    public static IServiceCollection AddAsiBackboneAspNetCore(
 38        this IServiceCollection services,
 39        Action<AsiBackboneAspNetCoreOptions> configure)
 40    {
 3941        ArgumentNullException.ThrowIfNull(services);
 3742        ArgumentNullException.ThrowIfNull(configure);
 43
 3544        AsiBackboneAspNetCoreOptions options = new();
 3545        configure(options);
 3546        options.Validate();
 47
 2948        _ = services.AddOptions<AsiBackboneAspNetCoreOptions>()
 2949            .Configure(configure)
 2950            .Validate(static options =>
 2951            {
 2952                try
 2953                {
 1554                    options.Validate();
 1555                    return true;
 2956                }
 057                catch (InvalidOperationException)
 2958                {
 059                    return false;
 2960                }
 1561            }, "ASP.NET Core integration options must be valid.")
 2962            .ValidateOnStart();
 63
 2964        _ = services.AddOptions<AsiBackboneHttpActorContextOptions>()
 2965            .Validate(static options =>
 2966            {
 2967                try
 2968                {
 1369                    options.Validate();
 1170                    return true;
 2971                }
 272                catch (InvalidOperationException)
 2973                {
 274                    return false;
 2975                }
 1376            }, "HTTP actor context options must be valid.")
 2977            .ValidateOnStart();
 78
 2979        _ = services.AddOptions<AsiBackboneHttpResultMappingOptions>()
 2980            .Validate(static options =>
 2981            {
 2982                try
 2983                {
 1384                    options.Validate();
 1185                    return true;
 2986                }
 287                catch (InvalidOperationException)
 2988                {
 289                    return false;
 2990                }
 1391            }, "HTTP result mapping options must be valid.")
 2992            .ValidateOnStart();
 93
 2994        _ = services.AddOptions<AsiBackboneAcknowledgmentChallengeOptions>()
 2995            .Validate(static options =>
 2996            {
 2997                try
 2998                {
 1399                    options.Validate();
 11100                    return true;
 29101                }
 2102                catch (InvalidOperationException)
 29103                {
 2104                    return false;
 29105                }
 13106            }, "Acknowledgment challenge options must be valid.")
 29107            .ValidateOnStart();
 108
 29109        _ = services.AddOptions<AsiBackboneEndpointGovernanceOptions>()
 29110            .Validate(static options =>
 29111            {
 29112                try
 29113                {
 9114                    options.Validate();
 9115                    return true;
 29116                }
 0117                catch (InvalidOperationException)
 29118                {
 0119                    return false;
 29120                }
 9121            }, "Endpoint governance options must be valid.")
 29122            .ValidateOnStart();
 123
 29124        _ = services.AddLogging();
 29125        _ = services.AddHttpContextAccessor();
 29126        _ = services.AddScoped<IAsiBackboneHttpActorContextResolver, HttpContextAsiBackboneActorContextResolver>();
 29127        _ = services.AddScoped<IAsiBackboneHttpRequestCorrelationResolver, HttpContextAsiBackboneRequestCorrelationResol
 29128        _ = services.AddScoped<IAsiBackboneAcknowledgmentChallengeService, DefaultAsiBackboneAcknowledgmentChallengeServ
 29129        _ = services.AddScoped<IAsiBackboneEndpointGovernanceService, DefaultAsiBackboneEndpointGovernanceService>();
 130
 29131        return services;
 132    }
 133
 134    /// <summary>
 135    /// Adds the host-owned governance outbox drain worker using default scheduling options.
 136    /// </summary>
 137    /// <param name="services">The service collection to add services to.</param>
 138    /// <returns>The same service collection so calls can be chained.</returns>
 139    public static IServiceCollection AddAsiBackboneGovernanceOutboxDrainWorker(this IServiceCollection services)
 140    {
 0141        return services.AddAsiBackboneGovernanceOutboxDrainWorker(_ => { });
 142    }
 143
 144    /// <summary>
 145    /// Adds the host-owned governance outbox drain worker using configured scheduling options.
 146    /// </summary>
 147    /// <param name="services">The service collection to add services to.</param>
 148    /// <param name="configure">The worker options configuration callback.</param>
 149    /// <returns>The same service collection so calls can be chained.</returns>
 150    /// <exception cref="ArgumentNullException">
 151    /// Thrown when <paramref name="services" /> or <paramref name="configure" /> is <see langword="null" />.
 152    /// </exception>
 153    public static IServiceCollection AddAsiBackboneGovernanceOutboxDrainWorker(
 154        this IServiceCollection services,
 155        Action<AsiBackboneGovernanceOutboxDrainWorkerOptions> configure)
 156    {
 14157        ArgumentNullException.ThrowIfNull(services);
 14158        ArgumentNullException.ThrowIfNull(configure);
 159
 14160        AsiBackboneGovernanceOutboxDrainWorkerOptions options = new();
 14161        configure(options);
 14162        options.Validate();
 163
 10164        _ = services.AddOptions<AsiBackboneGovernanceOutboxDrainWorkerOptions>()
 10165            .Configure(configure)
 10166            .Validate(static options =>
 10167            {
 10168                try
 10169                {
 10170                    options.Validate();
 10171                    return true;
 10172                }
 0173                catch (InvalidOperationException)
 10174                {
 0175                    return false;
 10176                }
 10177            }, "Governance outbox drain worker options must be valid.")
 10178            .ValidateOnStart();
 179
 10180        services.TryAddScoped<AsiBackboneGovernanceOutboxDrain>();
 10181        _ = services.AddHostedService<AsiBackboneGovernanceOutboxDrainHostedService>();
 182
 10183        return services;
 184    }
 185}