< 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
94%
Covered lines: 115
Uncovered lines: 7
Coverable lines: 122
Total lines: 200
Line coverage: 94.2%
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%1197.59%
AddAsiBackboneGovernanceOutboxDrainWorker(...)100%210%
AddAsiBackboneGovernanceOutboxDrainWorker(...)100%1189.18%

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    {
 10025        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    {
 4541        ArgumentNullException.ThrowIfNull(services);
 4442        ArgumentNullException.ThrowIfNull(configure);
 43
 4344        AsiBackboneAspNetCoreOptions options = new();
 4345        configure(options);
 4346        options.Validate();
 47
 4048        _ = services.AddOptions<AsiBackboneAspNetCoreOptions>()
 4049            .Configure(configure)
 4050            .Validate(static options =>
 4051            {
 4052                try
 4053                {
 2854                    options.Validate();
 2855                    return true;
 4056                }
 057                catch (InvalidOperationException)
 4058                {
 059                    return false;
 4060                }
 2861            }, "ASP.NET Core integration options must be valid.")
 4062            .ValidateOnStart();
 63
 4064        _ = services.AddOptions<AsiBackboneHttpActorContextOptions>()
 4065            .Validate(static options =>
 4066            {
 4067                try
 4068                {
 2569                    options.Validate();
 2470                    return true;
 4071                }
 172                catch (InvalidOperationException)
 4073                {
 174                    return false;
 4075                }
 2576            }, "HTTP actor context options must be valid.")
 4077            .ValidateOnStart();
 78
 4079        _ = services.AddOptions<AsiBackboneHttpResultMappingOptions>()
 4080            .Validate(static options =>
 4081            {
 4082                try
 4083                {
 2584                    options.Validate();
 2485                    return true;
 4086                }
 187                catch (InvalidOperationException)
 4088                {
 189                    return false;
 4090                }
 2591            }, "HTTP result mapping options must be valid.")
 4092            .ValidateOnStart();
 93
 4094        _ = services.AddOptions<AsiBackboneAcknowledgmentChallengeOptions>()
 4095            .Validate(static options =>
 4096            {
 4097                try
 4098                {
 2599                    options.Validate();
 24100                    return true;
 40101                }
 1102                catch (InvalidOperationException)
 40103                {
 1104                    return false;
 40105                }
 25106            }, "Acknowledgment challenge options must be valid.")
 40107            .ValidateOnStart();
 108
 40109        _ = services.AddOptions<AsiBackboneEndpointGovernanceOptions>()
 40110            .Validate(static options =>
 40111            {
 40112                try
 40113                {
 25114                    options.Validate();
 24115                    return true;
 40116                }
 1117                catch (InvalidOperationException)
 40118                {
 1119                    return false;
 40120                }
 25121            }, "Endpoint governance options must be valid.")
 40122            .ValidateOnStart();
 123
 40124        _ = services.AddLogging();
 40125        _ = services.AddHttpContextAccessor();
 40126        _ = services.AddScoped<IAsiBackboneHttpActorContextResolver, HttpContextAsiBackboneActorContextResolver>();
 40127        _ = services.AddScoped<IAsiBackboneHttpRequestCorrelationResolver, HttpContextAsiBackboneRequestCorrelationResol
 40128        _ = services.AddScoped<IAsiBackboneAcknowledgmentChallengeService, DefaultAsiBackboneAcknowledgmentChallengeServ
 40129        _ = services.AddScoped<IAsiBackboneEndpointGovernanceService, DefaultAsiBackboneEndpointGovernanceService>();
 130
 40131        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    {
 9157        ArgumentNullException.ThrowIfNull(services);
 9158        ArgumentNullException.ThrowIfNull(configure);
 159
 9160        AsiBackboneGovernanceOutboxDrainWorkerOptions options = new();
 9161        configure(options);
 9162        options.Validate();
 163
 7164        _ = services.AddOptions<AsiBackboneGovernanceOutboxDrainWorkerOptions>()
 7165            .Configure(configure)
 7166            .Validate(static options =>
 7167            {
 7168                try
 7169                {
 7170                    options.Validate();
 7171                    return true;
 7172                }
 0173                catch (InvalidOperationException)
 7174                {
 0175                    return false;
 7176                }
 7177            }, "Governance outbox drain worker options must be valid.")
 7178            .ValidateOnStart();
 179
 7180        _ = services.AddOptions<AsiBackboneGovernanceOutboxOptions>()
 7181            .Validate(static options =>
 7182            {
 7183                try
 7184                {
 3185                    options.Validate();
 3186                    return true;
 7187                }
 0188                catch (InvalidOperationException)
 7189                {
 0190                    return false;
 7191                }
 3192            }, "Governance outbox options must be valid.")
 7193            .ValidateOnStart();
 194
 7195        services.TryAddScoped<AsiBackboneGovernanceOutboxDrain>();
 7196        _ = services.AddHostedService<AsiBackboneGovernanceOutboxDrainHostedService>();
 197
 7198        return services;
 199    }
 200}