< Summary

Information
Class: Elsa.Tenants.TenantResolverPipelineBuilder
Assembly: Elsa.Tenants
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Services/TenantResolutionPipelineBuilder.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 47
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
get_Resolvers()100%210%
Append()100%210%
Append(...)0%620%
Clear()100%210%
Build(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Services/TenantResolutionPipelineBuilder.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4namespace Elsa.Tenants;
 5
 6/// <inheritdoc />
 7public class TenantResolverPipelineBuilder : ITenantResolverPipelineBuilder
 8{
 09    private readonly ISet<Type> _resolvers = new HashSet<Type>();
 10
 11    /// <inheritdoc />
 012    public IEnumerable<Type> Resolvers => _resolvers.ToList().AsReadOnly();
 13
 14    /// <inheritdoc />
 15    public ITenantResolverPipelineBuilder Append<T>() where T : ITenantResolver
 16    {
 017        var strategyType = typeof(T);
 018        return Append(strategyType);
 19    }
 20
 21    /// <inheritdoc />
 22    public ITenantResolverPipelineBuilder Append(Type resolverType)
 23    {
 024        if (typeof(ITenantResolver).IsAssignableFrom(resolverType) == false)
 025            throw new ArgumentException($"The type {resolverType} does not implement {nameof(ITenantResolver)}.");
 26
 027        _resolvers.Add(resolverType);
 028        return this;
 29    }
 30
 31    /// <inheritdoc />
 32    public ITenantResolverPipelineBuilder Clear()
 33    {
 034        _resolvers.Clear();
 035        return this;
 36    }
 37
 38    /// <inheritdoc />
 39    public IEnumerable<ITenantResolver> Build(IServiceProvider serviceProvider)
 40    {
 041        return _resolvers
 042            .Reverse()
 043            .Select(t => ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, t))
 044            .Cast<ITenantResolver>()
 045            .ToList();
 46    }
 47}