< Summary

Information
Class: ArturRios.Mediator.CommandQueryMediator
Assembly: ArturRios.Mediator
File(s): /home/runner/work/dotnet-mediator/dotnet-mediator/src/CommandQueryMediator.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 131
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 7
Fully covered methods: 7
Total methods: 7
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ExecuteCommand(...)100%11100%
ExecuteCommandAsync()100%11100%
ExecutePaginatedQuery(...)100%11100%
ExecutePaginatedQueryAsync()100%11100%
ExecuteQuery(...)100%11100%
ExecuteQueryAsync()100%11100%

File(s)

/home/runner/work/dotnet-mediator/dotnet-mediator/src/CommandQueryMediator.cs

#LineLine coverage
 1using ArturRios.Mediator.Command;
 2using ArturRios.Mediator.Query;
 3using ArturRios.Output;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace ArturRios.Mediator;
 7
 8/// <summary>
 9/// A unified entry point that combines the command and query mediators behind a single
 10/// type, enabling a CQRS-style separation of writes (commands) and reads (queries) while
 11/// only depending on one mediator.
 12/// </summary>
 13/// <remarks>
 14/// Register this type in your dependency injection container together with your command
 15/// and query handlers, then inject it wherever both commands and queries need to be
 16/// dispatched. Internally it delegates to a <see cref="CommandMediator"/> and a
 17/// <see cref="QueryMediator"/>, both built from the supplied scope factory.
 18/// </remarks>
 19/// <param name="scopeFactory">
 20/// The factory used to create dependency injection scopes for resolving handlers.
 21/// </param>
 2022public class CommandQueryMediator(IServiceScopeFactory scopeFactory)
 23{
 2024    private readonly CommandMediator _commandMediator = new(scopeFactory);
 2025    private readonly QueryMediator _queryMediator = new(scopeFactory);
 26
 27    /// <summary>
 28    /// Executes a command synchronously by delegating to the underlying <see cref="CommandMediator"/>.
 29    /// </summary>
 30    /// <typeparam name="TCommand">The command type to execute.</typeparam>
 31    /// <typeparam name="TOutput">The type of the data payload produced by the handler.</typeparam>
 32    /// <param name="command">The command instance to execute.</param>
 33    /// <returns>The <see cref="DataOutput{T}"/> returned by the resolved handler.</returns>
 34    public DataOutput<TOutput?> ExecuteCommand<TCommand, TOutput>(TCommand command)
 35        where TCommand : BaseCommand
 36        where TOutput : CommandOutput
 37    {
 138        return _commandMediator.ExecuteCommand<TCommand, TOutput>(command);
 39    }
 40
 41    /// <summary>
 42    /// Executes a command asynchronously by delegating to the underlying <see cref="CommandMediator"/>.
 43    /// </summary>
 44    /// <typeparam name="TCommand">The command type to execute.</typeparam>
 45    /// <typeparam name="TOutput">The type of the data payload produced by the handler.</typeparam>
 46    /// <param name="command">The command instance to execute.</param>
 47    /// <param name="cancellationToken">Cancels the execution, and the dispatch itself.</param>
 48    /// <returns>
 49    /// A task that resolves to the <see cref="DataOutput{T}"/> returned by the resolved handler.
 50    /// </returns>
 51    public async Task<DataOutput<TOutput?>> ExecuteCommandAsync<TCommand, TOutput>(
 52        TCommand command,
 53        CancellationToken cancellationToken = default)
 54        where TCommand : BaseCommand
 55        where TOutput : CommandOutput
 56    {
 3357        return await _commandMediator
 3358            .ExecuteCommandAsync<TCommand, TOutput>(command, cancellationToken)
 3359            .ConfigureAwait(false);
 3160    }
 61
 62    /// <summary>
 63    /// Executes a paginated query synchronously by delegating to the underlying <see cref="QueryMediator"/>.
 64    /// </summary>
 65    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 66    /// <typeparam name="TOutput">The type of the items in the paginated result.</typeparam>
 67    /// <param name="query">The query instance to execute, including the requested page metadata.</param>
 68    /// <returns>The <see cref="PaginatedOutput{T}"/> returned by the resolved handler.</returns>
 69    public PaginatedOutput<TOutput> ExecutePaginatedQuery<TQuery, TOutput>(TQuery query)
 70        where TQuery : BaseQuery
 71        where TOutput : QueryOutput
 72    {
 173        return _queryMediator.ExecutePaginatedQuery<TQuery, TOutput>(query);
 74    }
 75
 76    /// <summary>
 77    /// Executes a paginated query asynchronously by delegating to the underlying <see cref="QueryMediator"/>.
 78    /// </summary>
 79    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 80    /// <typeparam name="TOutput">The type of the items in the paginated result.</typeparam>
 81    /// <param name="query">The query instance to execute, including the requested page metadata.</param>
 82    /// <param name="cancellationToken">Cancels the execution, and the dispatch itself.</param>
 83    /// <returns>
 84    /// A task that resolves to the <see cref="PaginatedOutput{T}"/> returned by the resolved handler.
 85    /// </returns>
 86    public async Task<PaginatedOutput<TOutput>> ExecutePaginatedQueryAsync<TQuery, TOutput>(
 87        TQuery query,
 88        CancellationToken cancellationToken = default)
 89        where TQuery : BaseQuery
 90        where TOutput : QueryOutput
 91    {
 692        return await _queryMediator
 693            .ExecutePaginatedQueryAsync<TQuery, TOutput>(query, cancellationToken)
 694            .ConfigureAwait(false);
 595    }
 96
 97    /// <summary>
 98    /// Executes a single-result query synchronously by delegating to the underlying <see cref="QueryMediator"/>.
 99    /// </summary>
 100    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 101    /// <typeparam name="TOutput">The type of the data payload produced by the handler.</typeparam>
 102    /// <param name="query">The query instance to execute.</param>
 103    /// <returns>The <see cref="DataOutput{T}"/> returned by the resolved handler.</returns>
 104    public DataOutput<TOutput?> ExecuteQuery<TQuery, TOutput>(TQuery query)
 105        where TQuery : BaseQuery
 106        where TOutput : QueryOutput
 107    {
 1108        return _queryMediator.ExecuteQuery<TQuery, TOutput>(query);
 109    }
 110
 111    /// <summary>
 112    /// Executes a single-result query asynchronously by delegating to the underlying <see cref="QueryMediator"/>.
 113    /// </summary>
 114    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 115    /// <typeparam name="TOutput">The type of the data payload produced by the handler.</typeparam>
 116    /// <param name="query">The query instance to execute.</param>
 117    /// <param name="cancellationToken">Cancels the execution, and the dispatch itself.</param>
 118    /// <returns>
 119    /// A task that resolves to the <see cref="DataOutput{T}"/> returned by the resolved handler.
 120    /// </returns>
 121    public async Task<DataOutput<TOutput?>> ExecuteQueryAsync<TQuery, TOutput>(
 122        TQuery query,
 123        CancellationToken cancellationToken = default)
 124        where TQuery : BaseQuery
 125        where TOutput : QueryOutput
 126    {
 5127        return await _queryMediator
 5128            .ExecuteQueryAsync<TQuery, TOutput>(query, cancellationToken)
 5129            .ConfigureAwait(false);
 4130    }
 131}