< Summary

Information
Class: Elsa.Workflows.Pipelines.WorkflowExecution.WorkflowExecutionMiddlewareExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Pipelines/WorkflowExecution/WorkflowExecutionMiddlewareExtensions.cs
Line coverage
89%
Covered lines: 17
Uncovered lines: 2
Coverable lines: 19
Total lines: 68
Line coverage: 89.4%
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%
ReplaceTerminal(...)100%11100%
Replace(...)100%11100%
CreateMiddlewareDelegateFactory(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Pipelines/WorkflowExecution/WorkflowExecutionMiddlewareExtensions.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace Elsa.Workflows.Pipelines.WorkflowExecution;
 5
 6/// <summary>
 7/// Provides extensions to <see cref="IWorkflowExecutionPipelineBuilder"/> that adds support for installing <see cref="I
 8/// </summary>
 9public static class WorkflowExecutionMiddlewareExtensions
 10{
 11    extension(IWorkflowExecutionPipelineBuilder pipelineBuilder)
 12    {
 13        /// <summary>
 14        /// Installs the specified middleware component into the pipeline being built.
 15        /// </summary>
 16        public IWorkflowExecutionPipelineBuilder UseMiddleware<[DynamicallyAccessedMembers(DynamicallyAccessedMemberType
 17        {
 212518            var delegateFactory = CreateMiddlewareDelegateFactory<TMiddleware>(pipelineBuilder, args);
 212519            return pipelineBuilder.Use(delegateFactory);
 20        }
 21
 22        /// <summary>
 23        /// Installs the specified middleware component into the pipeline being built.
 24        /// </summary>
 25        public IWorkflowExecutionPipelineBuilder Insert<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Publi
 26        {
 027            var delegateFactory = CreateMiddlewareDelegateFactory<TMiddleware>(pipelineBuilder, args);
 028            return pipelineBuilder.Insert(index, delegateFactory);
 29        }
 30
 31        /// <summary>
 32        /// Replaces the terminal middleware component with the specified middleware component.
 33        /// </summary>
 34        public IWorkflowExecutionPipelineBuilder ReplaceTerminal<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTy
 35        {
 436            var index = pipelineBuilder.Components.Count() - 1;
 437            return pipelineBuilder.Replace<TMiddleware>(index, args);
 38        }
 39
 40        /// <summary>
 41        /// Replaces the middleware component at the specified index with the specified middleware component.
 42        /// </summary>
 43        public IWorkflowExecutionPipelineBuilder Replace<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Publ
 44        {
 445            var delegateFactory = CreateMiddlewareDelegateFactory<TMiddleware>(pipelineBuilder, args);
 446            return pipelineBuilder.Replace(index, delegateFactory);
 47        }
 48
 49        /// <summary>
 50        /// Creates a middleware delegate for the specified middleware component.
 51        /// </summary>
 52        public Func<WorkflowMiddlewareDelegate, WorkflowMiddlewareDelegate> CreateMiddlewareDelegateFactory<[Dynamically
 53        {
 212954            var middleware = typeof(TMiddleware);
 55
 212956            return next =>
 212957            {
 212558                var invokeMethod = MiddlewareHelpers.GetInvokeMethod(middleware);
 212559                var ctorParams = new[]
 212560                {
 212561                    next
 212562                }.Concat(args).ToArray();
 212563                var instance = ActivatorUtilities.CreateInstance(pipelineBuilder.ServiceProvider, middleware, ctorParams
 212564                return (WorkflowMiddlewareDelegate)invokeMethod.CreateDelegate(typeof(WorkflowMiddlewareDelegate), insta
 212965            };
 66        }
 67    }
 68}