< Summary

Information
Class: ProjectTemplate.Infrastructure.Data.Extensions.ApplicationAuditCompletionOutboxServiceExtensions
Assembly: ProjectTemplate.Infrastructure
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/Extensions/ApplicationAuditCompletionOutboxServiceExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 33
Coverable lines: 33
Total lines: 64
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddApplicationAuditCompletionOutboxCore(...)0%2040%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/Extensions/ApplicationAuditCompletionOutboxServiceExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.DependencyInjection.Extensions;
 3using Microsoft.Extensions.Options;
 4using ProjectTemplate.Infrastructure.Data.Auditing;
 5
 6namespace ProjectTemplate.Infrastructure.Data.Extensions;
 7
 8/// <summary>
 9/// Provides opt-in registration for durable audit-completion outbox services.
 10/// </summary>
 11public static class ApplicationAuditCompletionOutboxServiceExtensions
 12{
 13    /// <summary>
 14    /// Registers durable staging, dispatch, and minimized operational query services.
 15    /// </summary>
 16    /// <remarks>
 17    /// Call <see cref="InfrastructureDataAccessServiceExtensions" /> before this method.
 18    /// This infrastructure registration does not start a background dispatcher loop.
 19    /// </remarks>
 20    public static IServiceCollection AddApplicationAuditCompletionOutboxCore(
 21        this IServiceCollection services,
 22        Action<ApplicationAuditCompletionOutboxOptions>? configure = null)
 23    {
 024        ArgumentNullException.ThrowIfNull(services);
 25
 026        OptionsBuilder<ApplicationAuditCompletionOutboxOptions> optionsBuilder = services
 027            .AddOptions<ApplicationAuditCompletionOutboxOptions>()
 028            .Validate(options => !string.IsNullOrWhiteSpace(options.DefaultDestination),
 029                "The default audit-completion destination must not be empty.")
 030            .Validate(options => options.DefaultDestination.Length <= 128,
 031                "The default audit-completion destination cannot exceed 128 characters.")
 032            .Validate(options => options.BatchSize > 0,
 033                "The audit-completion outbox batch size must be greater than zero.")
 034            .Validate(options => options.PollInterval > TimeSpan.Zero,
 035                "The audit-completion polling interval must be greater than zero.")
 036            .Validate(options => options.BaseRetryDelay > TimeSpan.Zero,
 037                "The base audit-completion retry delay must be greater than zero.")
 038            .Validate(options => options.MaxRetryDelay >= options.BaseRetryDelay,
 039                "The maximum audit-completion retry delay must not be less than the base delay.")
 040            .Validate(options => options.DeferredRetryDelay > TimeSpan.Zero,
 041                "The deferred audit-completion retry delay must be greater than zero.")
 042            .Validate(options => options.MaxRetryAttempts > 0,
 043                "The maximum audit-completion retry attempts must be greater than zero.")
 044            .Validate(options => options.MaxErrorDetailLength is > 0 and <= 512,
 045                "The audit-completion error detail length must be between 1 and 512 characters.")
 046            .ValidateOnStart();
 47
 048        if (configure is not null)
 49        {
 050            optionsBuilder.Configure(configure);
 51        }
 52
 053        services.TryAddSingleton(TimeProvider.System);
 054        services.TryAddScoped<ApplicationAuditCompletionOutbox>();
 055        services.TryAddScoped<IApplicationAuditCompletionOutbox>(serviceProvider =>
 056            serviceProvider.GetRequiredService<ApplicationAuditCompletionOutbox>());
 057        services.TryAddScoped<IApplicationAuditCompletionOutboxDispatcher>(serviceProvider =>
 058            serviceProvider.GetRequiredService<ApplicationAuditCompletionOutbox>());
 059        services.TryAddScoped<IApplicationAuditCompletionOutboxQuery>(serviceProvider =>
 060            serviceProvider.GetRequiredService<ApplicationAuditCompletionOutbox>());
 61
 062        return services;
 63    }
 64}