< 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
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 66
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddApplicationAuditCompletionOutboxCore(...)100%22100%

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    {
 424        ArgumentNullException.ThrowIfNull(services);
 25
 326        OptionsBuilder<ApplicationAuditCompletionOutboxOptions> optionsBuilder = services
 327            .AddOptions<ApplicationAuditCompletionOutboxOptions>()
 328            .Validate(options => !string.IsNullOrWhiteSpace(options.DefaultDestination),
 329                "The default audit-completion destination must not be empty.")
 330            .Validate(options => options.DefaultDestination.Length <= 128,
 331                "The default audit-completion destination cannot exceed 128 characters.")
 332            .Validate(options => options.BatchSize > 0,
 333                "The audit-completion outbox batch size must be greater than zero.")
 334            .Validate(options => options.PollInterval > TimeSpan.Zero,
 335                "The audit-completion polling interval must be greater than zero.")
 336            .Validate(options => options.MaximumCycleRetryDelay >= options.PollInterval,
 337                "The maximum audit-completion cycle retry delay must not be less than the polling interval.")
 338            .Validate(options => options.BaseRetryDelay > TimeSpan.Zero,
 339                "The base audit-completion retry delay must be greater than zero.")
 340            .Validate(options => options.MaxRetryDelay >= options.BaseRetryDelay,
 341                "The maximum audit-completion retry delay must not be less than the base delay.")
 342            .Validate(options => options.DeferredRetryDelay > TimeSpan.Zero,
 343                "The deferred audit-completion retry delay must be greater than zero.")
 344            .Validate(options => options.MaxRetryAttempts > 0,
 345                "The maximum audit-completion retry attempts must be greater than zero.")
 346            .Validate(options => options.MaxErrorDetailLength is > 0 and <= 512,
 347                "The audit-completion error detail length must be between 1 and 512 characters.")
 348            .ValidateOnStart();
 49
 350        if (configure is not null)
 51        {
 252            optionsBuilder.Configure(configure);
 53        }
 54
 355        services.TryAddSingleton(TimeProvider.System);
 356        services.TryAddScoped<ApplicationAuditCompletionOutbox>();
 357        services.TryAddScoped<IApplicationAuditCompletionOutbox>(serviceProvider =>
 358            serviceProvider.GetRequiredService<ApplicationAuditCompletionOutbox>());
 359        services.TryAddScoped<IApplicationAuditCompletionOutboxDispatcher>(serviceProvider =>
 360            serviceProvider.GetRequiredService<ApplicationAuditCompletionOutbox>());
 361        services.TryAddScoped<IApplicationAuditCompletionOutboxQuery>(serviceProvider =>
 362            serviceProvider.GetRequiredService<ApplicationAuditCompletionOutbox>());
 63
 364        return services;
 65    }
 66}