< Summary

Information
Class: NexMediator.Core.DefaultNexMediator
Assembly: NexMediator.Core
File(s): /home/runner/work/NexMediator/NexMediator/src/NexMediator.Core/DefaultNexMediator.cs
Line coverage
95%
Covered lines: 22
Uncovered lines: 1
Coverable lines: 23
Total lines: 80
Line coverage: 95.6%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)83.33%6687.5%
Send(...)100%22100%
Publish(...)100%22100%
Stream(...)100%22100%

File(s)

/home/runner/work/NexMediator/NexMediator/src/NexMediator.Core/DefaultNexMediator.cs

#LineLine coverage
 1using NexMediator.Abstractions.Interfaces;
 2using NexMediator.Core.Internal;
 3
 4namespace NexMediator.Core;
 5
 6/// <summary>
 7/// Default implementation of INexMediator.
 8/// Routes requests, notifications, and streams through a cached pipeline delegate.
 9/// </summary>
 10public class DefaultNexMediator : INexMediator
 11{
 12    private readonly IServiceProvider _provider;
 13    private readonly NexMediatorOptions _options;
 14
 15    /// <summary>
 16    /// Initializes a new DefaultNexMediator instance.
 17    /// Validates pipeline options at startup and throws if invalid.
 18    /// </summary>
 19    /// <param name="provider">
 20    /// Service provider for resolving handlers, behaviors, and scoped services.
 21    /// </param>
 22    /// <param name="options">
 23    /// Configuration options for the mediator pipeline.
 24    /// </param>
 1925    public DefaultNexMediator(IServiceProvider provider, NexMediatorOptions options)
 1926    {
 1927        _provider = provider ?? throw new ArgumentNullException(nameof(provider));
 1828        _options = options ?? throw new ArgumentNullException(nameof(options));
 29
 1730        var warnings = _options.Validate();
 1731        if (warnings.Count > 0)
 032            throw new InvalidOperationException($"Pipeline configuration validation failed: {string.Join("; ", warnings)
 1733    }
 34
 35    /// <summary>
 36    /// Sends a request through the compiled, cached pipeline and returns its response.
 37    /// </summary>
 38    /// <typeparam name="TResponse">Type of the response.</typeparam>
 39    /// <param name="request">The request to send.</param>
 40    /// <param name="cancellationToken">Token to cancel the operation.</param>
 41    /// <returns>The response from the handler.</returns>
 42    public Task<TResponse> Send<TResponse>(INexRequest<TResponse> request, CancellationToken cancellationToken = default
 943    {
 944        if (request == null)
 145            throw new ArgumentNullException(nameof(request));
 46
 847        return NexRequestExecutor.Dispatch(request, _provider, cancellationToken);
 848    }
 49
 50    /// <summary>
 51    /// Publishes a notification through the pipeline without caching.
 52    /// </summary>
 53    /// <typeparam name="TNotification">Type of the notification.</typeparam>
 54    /// <param name="notification">The notification to publish.</param>
 55    /// <param name="cancellationToken">Token to cancel the operation.</param>
 56    /// <returns>A task representing the publish operation.</returns>
 57    public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default)
 58        where TNotification : INexNotification
 359    {
 360        if (notification == null)
 161            throw new ArgumentNullException(nameof(notification));
 62
 263        return NexNotificationExecutor.Publish(notification, _provider, cancellationToken);
 264    }
 65
 66    /// <summary>
 67    /// Streams responses for a stream request through the pipeline without caching.
 68    /// </summary>
 69    /// <typeparam name="TResponse">Type of each streamed response.</typeparam>
 70    /// <param name="request">The stream request.</param>
 71    /// <param name="cancellationToken">Token to cancel the operation.</param>
 72    /// <returns>An async enumerable of responses.</returns>
 73    public IAsyncEnumerable<TResponse> Stream<TResponse>(INexStreamRequest<TResponse> request, CancellationToken cancell
 474    {
 475        if (request == null)
 176            throw new ArgumentNullException(nameof(request));
 77
 378        return NexStreamExecutor.Execute(request, _provider, cancellationToken);
 279    }
 80}