< Summary

Information
Class: Elsa.Workflows.Pipelines.ActivityExecution.ActivityExecutionMiddlewareExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Pipelines/ActivityExecution/ActivityExecutionMiddlewareExtensions.cs
Line coverage
86%
Covered lines: 13
Uncovered lines: 2
Coverable lines: 15
Total lines: 41
Line coverage: 86.6%
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
UseMiddleware(...)100%11100%
Insert(...)100%210%
CreateMiddlewareDelegateFactory(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Pipelines/ActivityExecution/ActivityExecutionMiddlewareExtensions.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace Elsa.Workflows.Pipelines.ActivityExecution;
 5
 6public static class ActivityExecutionMiddlewareExtensions
 7{
 8    extension(IActivityExecutionPipelineBuilder pipelineBuilder)
 9    {
 10        public IActivityExecutionPipelineBuilder UseMiddleware<[DynamicallyAccessedMembers(DynamicallyAccessedMemberType
 11        {
 210512            var delegateFactory = CreateMiddlewareDelegateFactory<TMiddleware>(pipelineBuilder, args);
 210513            return pipelineBuilder.Use(delegateFactory);
 14        }
 15
 16        public IActivityExecutionPipelineBuilder Insert<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Publi
 17        {
 018            var delegateFactory = CreateMiddlewareDelegateFactory<TMiddleware>(pipelineBuilder, args);
 019            return pipelineBuilder.Insert(index, delegateFactory);
 20        }
 21
 22        /// <summary>
 23        /// Creates a middleware delegate for the specified middleware component.
 24        /// </summary>
 25        public Func<ActivityMiddlewareDelegate, ActivityMiddlewareDelegate> CreateMiddlewareDelegateFactory<[Dynamically
 26        {
 210527            var middleware = typeof(TMiddleware);
 28
 210529            return next =>
 210530            {
 210531                var invokeMethod = MiddlewareHelpers.GetInvokeMethod(middleware);
 210532                var ctorArgs = new[]
 210533                {
 210534                    next
 210535                }.Concat(args).ToArray();
 210536                var instance = ActivatorUtilities.CreateInstance(pipelineBuilder.ServiceProvider, middleware, ctorArgs);
 210537                return (ActivityMiddlewareDelegate)invokeMethod.CreateDelegate(typeof(ActivityMiddlewareDelegate), insta
 210538            };
 39        }
 40    }
 41}