< 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.
 1131621        var notification = context.Notification;
 1131622        var notificationType = notification.GetType();
 1131623        var handlerType = typeof(INotificationHandler<>).MakeGenericType(notificationType);
 1131624        var serviceProvider = context.ServiceProvider;
 1131625        var notificationHandlers = serviceProvider.GetServices<INotificationHandler>();
 54458526        var handlers = notificationHandlers.Where(x => handlerType.IsInstanceOfType(x)).DistinctBy(x => x.GetType()).ToA
 1131627        var strategyContext = new NotificationStrategyContext(context, handlers, logger, serviceProvider, context.Cancel
 28
 1131629        await context.NotificationStrategy.PublishAsync(strategyContext);
 30
 31        // Invoke next middleware.
 1131632        await next(context);
 1131633    }
 34}