< Summary

Information
Class: Elsa.Extensions.ModuleExtensions
Assembly: Elsa.Api.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Api.Common/Extensions/ModuleExtensions.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 65
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
.cctor()100%11100%
AddFastEndpointsAssembly(...)100%11100%
AddFastEndpointsAssembly(...)100%11100%
AddFastEndpointsAssembly(...)100%11100%
GetFastEndpointsAssembliesFromModule(...)100%11100%
AddFastEndpointsFromModule(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Api.Common/Extensions/ModuleExtensions.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Features.Services;
 3using Elsa.Permissions;
 4using FastEndpoints;
 5using Microsoft.Extensions.DependencyInjection;
 6
 7// ReSharper disable once CheckNamespace
 8namespace Elsa.Extensions;
 9
 10/// <summary>
 11/// Provides extensions to <see cref="IModule"/>.
 12/// </summary>
 13public static class ModuleExtensions
 14{
 115    private static readonly object FastEndpointsAssembliesKey = new();
 16
 17    /// <summary>
 18    /// Registers the specified assembly for FastEndpoint assembly discovery.
 19    /// </summary>
 20    public static IModule AddFastEndpointsAssembly(this IModule module, Assembly assembly)
 21    {
 2122        var assemblies = module.Properties.GetOrAdd(FastEndpointsAssembliesKey, () => new HashSet<Assembly>());
 1823        assemblies.Add(assembly);
 24
 25        // Registering an endpoint assembly is what guarantees its permissions work, so the evaluator and
 26        // that assembly's descriptors are registered here rather than in AddFastEndpointsFromModule. A host
 27        // that wires FastEndpoints itself never calls that helper, and without the authorization handler
 28        // every RequirePermission endpoint would answer 403 -- fail-closed, but broken.
 1829        module.Services.AddElsaAuthorization();
 1830        module.Services.AddPermissionDescriptorsFromAssembly(assembly);
 31
 1832        return module;
 33    }
 34
 35    /// <summary>
 36    /// Registers the assembly for FastEndpoint assembly discovery using the specified marker type.
 37    /// </summary>
 1238    public static IModule AddFastEndpointsAssembly<T>(this IModule module) => module.AddFastEndpointsAssembly(typeof(T))
 39
 40    /// <summary>
 41    /// Registers the assembly for FastEndpoint assembly discovery using the specified marker type.
 42    /// </summary>
 1843    public static IModule AddFastEndpointsAssembly(this IModule module, Type markerType) => module.AddFastEndpointsAssem
 44
 45    /// <summary>
 46    /// Returns all collected assemblies for discovery of endpoints.
 47    /// </summary>
 648    public static IEnumerable<Assembly> GetFastEndpointsAssembliesFromModule(this IModule module) => module.Properties.G
 49
 50    /// <summary>
 51    /// Adds FastEndpoints to the service container and registers all collected assemblies for discovery of endpoints.
 52    /// </summary>
 53    public static IModule AddFastEndpointsFromModule(this IModule module)
 54    {
 655        var assemblies = module.GetFastEndpointsAssembliesFromModule().ToList();
 56
 657        module.Services.AddFastEndpoints(options =>
 658        {
 659            options.DisableAutoDiscovery = true;
 660            options.Assemblies = assemblies;
 1261        });
 62
 663        return module;
 64    }
 65}