< Summary

Information
Class: Elsa.Mediator.Middleware.Notification.Components.NotificationHandlerInvokerMiddleware
Assembly: Elsa.Mediator
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Notification/Components/NotificationHandlerInvokerMiddleware.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 34
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/Notification/Components/NotificationHandlerInvokerMiddleware.cs

#LineLine coverage
 1using Elsa.Mediator.Contexts;
 2using Elsa.Mediator.Contracts;
 3using Elsa.Mediator.Middleware.Notification.Contracts;
 4using JetBrains.Annotations;
 5using Microsoft.Extensions.DependencyInjection;
 6using Microsoft.Extensions.Logging;
 7
 8namespace Elsa.Mediator.Middleware.Notification.Components;
 9
 10/// <inheritdoc />
 11[UsedImplicitly]
 112public class NotificationHandlerInvokerMiddleware(
 113    NotificationMiddlewareDelegate next,
 114    ILogger<NotificationHandlerInvokerMiddleware> logger)
 15    : INotificationMiddleware
 16{
 17    /// <inheritdoc />
 18    public async ValueTask InvokeAsync(NotificationContext context)
 19    {
 20        // Find all handlers for the specified notification.
 1255221        var notification = context.Notification;
 1255222        var notificationType = notification.GetType();
 1255223        var handlerType = typeof(INotificationHandler<>).MakeGenericType(notificationType);
 1255224        var serviceProvider = context.ServiceProvider;
 1255225        var notificationHandlers = serviceProvider.GetServices<INotificationHandler>();
 60407426        var handlers = notificationHandlers.Where(x => handlerType.IsInstanceOfType(x)).DistinctBy(x => x.GetType()).ToA
 1255227        var strategyContext = new NotificationStrategyContext(context, handlers, logger, serviceProvider, context.Cancel
 28
 1255229        await context.NotificationStrategy.PublishAsync(strategyContext);
 30
 31        // Invoke next middleware.
 1255232        await next(context);
 1255233    }
 34}