< Summary

Information
Class: Elsa.Extensions.WorkflowDictionaryExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/WorkflowDictionaryExtensions.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Add(...)100%22100%
Add(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/WorkflowDictionaryExtensions.cs

#LineLine coverage
 1using Elsa.Workflows;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4// ReSharper disable once CheckNamespace
 5namespace Elsa.Extensions;
 6
 7/// <summary>
 8/// Extension methods for <see cref="IDictionary{TKey,TValue}"/>.
 9/// </summary>
 10public static class WorkflowDictionaryExtensions
 11{
 12    /// <summary>
 13    /// Register a workflow factory that creates an instance of the specified workflow type.
 14    /// </summary>
 15    public static void Add<TWorkflow>(this IDictionary<string, Func<IServiceProvider, ValueTask<IWorkflow>>> dictionary)
 16    {
 17        // FullName should never be null here, as we filter out generic types
 918        dictionary.Add(typeof(TWorkflow).FullName!, sp =>
 919        {
 2420            var workflow = ActivatorUtilities.GetServiceOrCreateInstance<TWorkflow>(sp);
 2421            return new ValueTask<IWorkflow>(workflow);
 922        });
 923    }
 24
 25    /// <summary>
 26    /// Register a workflow factory that creates an instance of the specified workflow type.
 27    /// </summary>
 28    public static void Add(this IDictionary<string, Func<IServiceProvider, ValueTask<IWorkflow>>> dictionary, Type workf
 29    {
 30        // FullName should never be null here, as we filter out generic types
 4931        dictionary.Add(workflowType.FullName!, sp =>
 4932        {
 39233            var workflow = (IWorkflow)ActivatorUtilities.GetServiceOrCreateInstance(sp, workflowType);
 39234            return new ValueTask<IWorkflow>(workflow);
 4935        });
 4936    }
 37}