< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.Command.Auditing.CommandHandlerRegistrationExtensions
Assembly: ArturRios.Heimdall.Command
File(s): /home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Auditing/CommandHandlerRegistrationExtensions.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 34
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 1
Fully covered methods: 1
Total methods: 1
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddAuditedCommandHandler(...)100%11100%

File(s)

/home/runner/work/heimdall-api/heimdall-api/src/Application/ArturRios.Heimdall.Command/Auditing/CommandHandlerRegistrationExtensions.cs

#LineLine coverage
 1using ArturRios.Mediator.Command;
 2using ArturRios.Mediator.Command.Interfaces;
 3using Microsoft.Extensions.DependencyInjection;
 4
 5namespace ArturRios.Heimdall.Command.Auditing;
 6
 7public static class CommandHandlerRegistrationExtensions
 8{
 9    /// <summary>
 10    ///     Registers <typeparamref name="THandler" /> and wraps it with <see cref="AuditingCommandHandler{TCommand,TOut
 11    ///     so every command handler produces an audit trail entry on success (NFR-09), without any
 12    ///     change to the handler itself.
 13    ///     The concrete <typeparamref name="THandler" /> registration this method also creates is an
 14    ///     implementation detail, kept only so the decorator factory above can resolve it; callers should
 15    ///     always depend on <see cref="ICommandHandlerAsync{TCommand,TOutput}" /> and never resolve
 16    ///     <typeparamref name="THandler" /> directly, or auditing is silently bypassed.
 17    /// </summary>
 18    public static IServiceCollection AddAuditedCommandHandler<TCommand, TOutput, THandler>(
 19        this IServiceCollection services)
 20        where TCommand : BaseCommand
 21        where TOutput : CommandOutput
 22        where THandler : class, ICommandHandlerAsync<TCommand, TOutput>
 23    {
 4854624        services.AddScoped<THandler>();
 4854625        services.AddScoped<ICommandHandlerAsync<TCommand, TOutput>>(provider =>
 4952526            new AuditingCommandHandler<TCommand, TOutput>(
 4952527                provider.GetRequiredService<THandler>(),
 4952528                provider.GetRequiredService<IAuditLogWriter>(),
 4952529                provider.GetRequiredService<
 4952530                    Microsoft.Extensions.Logging.ILogger<AuditingCommandHandler<TCommand, TOutput>>>()));
 31
 4854632        return services;
 33    }
 34}