< Summary

Information
Class: ArturRios.Mediator.CommandQueryMediator
Assembly: ArturRios.Mediator
File(s): D:\Repositories\dotnet-mediator\src\CommandQueryMediator.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 116
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: 6
Total methods: 7
Method coverage: 100%
Full method coverage: 85.7%

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)

D:\Repositories\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>
 622public class CommandQueryMediator(IServiceScopeFactory scopeFactory)
 23{
 624    private readonly CommandMediator _commandMediator = new(scopeFactory);
 625    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
 137    {
 138        return _commandMediator.ExecuteCommand<TCommand, TOutput>(command);
 139    }
 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    /// <returns>
 48    /// A task that resolves to the <see cref="DataOutput{T}"/> returned by the resolved handler.
 49    /// </returns>
 50    public async Task<DataOutput<TOutput?>> ExecuteCommandAsync<TCommand, TOutput>(TCommand command)
 51        where TCommand : BaseCommand
 52        where TOutput : CommandOutput
 153    {
 154        return await _commandMediator.ExecuteCommandAsync<TCommand, TOutput>(command);
 155    }
 56
 57    /// <summary>
 58    /// Executes a paginated query synchronously by delegating to the underlying <see cref="QueryMediator"/>.
 59    /// </summary>
 60    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 61    /// <typeparam name="TOutput">The type of the items in the paginated result.</typeparam>
 62    /// <param name="query">The query instance to execute, including the requested page metadata.</param>
 63    /// <returns>The <see cref="PaginatedOutput{T}"/> returned by the resolved handler.</returns>
 64    public PaginatedOutput<TOutput> ExecutePaginatedQuery<TQuery, TOutput>(TQuery query)
 65        where TQuery : BaseQuery
 66        where TOutput : QueryOutput
 167    {
 168        return _queryMediator.ExecutePaginatedQuery<TQuery, TOutput>(query);
 169    }
 70
 71    /// <summary>
 72    /// Executes a paginated query asynchronously by delegating to the underlying <see cref="QueryMediator"/>.
 73    /// </summary>
 74    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 75    /// <typeparam name="TOutput">The type of the items in the paginated result.</typeparam>
 76    /// <param name="query">The query instance to execute, including the requested page metadata.</param>
 77    /// <returns>
 78    /// A task that resolves to the <see cref="PaginatedOutput{T}"/> returned by the resolved handler.
 79    /// </returns>
 80    public async Task<PaginatedOutput<TOutput>> ExecutePaginatedQueryAsync<TQuery, TOutput>(TQuery query)
 81        where TQuery : BaseQuery
 82        where TOutput : QueryOutput
 183    {
 184        return await _queryMediator.ExecutePaginatedQueryAsync<TQuery, TOutput>(query);
 185    }
 86
 87    /// <summary>
 88    /// Executes a single-result query synchronously by delegating to the underlying <see cref="QueryMediator"/>.
 89    /// </summary>
 90    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 91    /// <typeparam name="TOutput">The type of the data payload produced by the handler.</typeparam>
 92    /// <param name="query">The query instance to execute.</param>
 93    /// <returns>The <see cref="DataOutput{T}"/> returned by the resolved handler.</returns>
 94    public DataOutput<TOutput?> ExecuteQuery<TQuery, TOutput>(TQuery query)
 95        where TQuery : BaseQuery
 96        where TOutput : QueryOutput
 197    {
 198        return _queryMediator.ExecuteQuery<TQuery, TOutput>(query);
 199    }
 100
 101    /// <summary>
 102    /// Executes a single-result query asynchronously by delegating to the underlying <see cref="QueryMediator"/>.
 103    /// </summary>
 104    /// <typeparam name="TQuery">The query type to execute.</typeparam>
 105    /// <typeparam name="TOutput">The type of the data payload produced by the handler.</typeparam>
 106    /// <param name="query">The query instance to execute.</param>
 107    /// <returns>
 108    /// A task that resolves to the <see cref="DataOutput{T}"/> returned by the resolved handler.
 109    /// </returns>
 110    public async Task<DataOutput<TOutput?>> ExecuteQueryAsync<TQuery, TOutput>(TQuery query)
 111        where TQuery : BaseQuery
 112        where TOutput : QueryOutput
 1113    {
 1114        return await _queryMediator.ExecuteQueryAsync<TQuery, TOutput>(query);
 1115    }
 116}