< Summary

Information
Class: Elsa.Extensions.ModuleExtensions
Assembly: Elsa
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa/Extensions/DependencyInjectionExtensions.cs
Line coverage
64%
Covered lines: 9
Uncovered lines: 5
Coverable lines: 14
Total lines: 50
Line coverage: 64.2%
Branch coverage
25%
Covered branches: 1
Total branches: 4
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
AddElsa(...)100%11100%
ConfigureElsa(...)0%620%
GetOrCreateModule(...)50%2280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa/Extensions/DependencyInjectionExtensions.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using Elsa.Features;
 3using Elsa.Features.Services;
 4using Microsoft.Extensions.DependencyInjection;
 5
 6namespace Elsa.Extensions;
 7
 8/// <summary>
 9/// Provides extension methods to <see cref="IServiceCollection"/>.
 10/// </summary>
 11public static class ModuleExtensions
 12{
 113    private static readonly IDictionary<IServiceCollection, IModule> Modules = new ConcurrentDictionary<IServiceCollecti
 14
 15    /// <summary>
 16    /// Creates a new Elsa module and adds the <see cref="ElsaFeature"/> to it.
 17    /// </summary>
 18    public static IModule AddElsa(this IServiceCollection services, Action<IModule>? configure = null)
 19    {
 120        var module = services.GetOrCreateModule();
 221        module.Configure<AppFeature>(app => app.Configurator += configure);
 122        module.Apply();
 23
 124        return module;
 25    }
 26
 27    /// <summary>
 28    /// Configures the Elsa module.
 29    /// </summary>
 30    public static IModule ConfigureElsa(this IServiceCollection services, Action<IModule>? configure = null)
 31    {
 032        var module = services.GetOrCreateModule();
 33
 034        if(configure != null)
 035            module.Configure<AppFeature>(app => app.Configurator += configure);
 36
 037        return module;
 38    }
 39
 40    private static IModule GetOrCreateModule(this IServiceCollection services)
 41    {
 142        if(Modules.TryGetValue(services, out var module))
 043            return module;
 44
 145        module = services.CreateModule();
 46
 147        Modules[services] = module;
 148        return module;
 49    }
 50}