< Summary

Information
Class: Elsa.Tenants.AspNetCore.Features.MultitenantHttpRoutingFeature
Assembly: Elsa.Tenants.AspNetCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants.AspNetCore/Features/MultitenantHttpRoutingFeature.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 58
Line coverage: 0%
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
.ctor(...)100%210%
WithTenantHeader(...)100%210%
WithMultitenancyHttpOptions(...)100%210%
Configure()100%210%
Apply()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants.AspNetCore/Features/MultitenantHttpRoutingFeature.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Features.Abstractions;
 3using Elsa.Features.Attributes;
 4using Elsa.Features.Services;
 5using Elsa.Http.Features;
 6using Elsa.Tenants.AspNetCore.Options;
 7using Elsa.Tenants.AspNetCore.Services;
 8using Elsa.Tenants.Features;
 9using Microsoft.Extensions.DependencyInjection;
 10
 11namespace Elsa.Tenants.AspNetCore.Features;
 12
 13[DependencyOf(typeof(HttpFeature))]
 14[DependencyOf(typeof(TenantsFeature))]
 015public class MultitenantHttpRoutingFeature(IModule module) : FeatureBase(module)
 16{
 017    private Action<MultitenancyHttpOptions> _configureMultitenancyHttpOptions = _ => { };
 18
 19    /// <summary>
 20    /// Configures the MultitenantHttpRoutingFeature to use a specific tenant header name.
 21    /// </summary>
 22    /// <param name="headerName">The name of the HTTP header used to identify the tenant.</param>
 23    /// <returns>The current instance of <see cref="MultitenantHttpRoutingFeature"/> for fluent configuration.</returns>
 024    public MultitenantHttpRoutingFeature WithTenantHeader(string headerName) => WithMultitenancyHttpOptions(options => o
 25
 26    /// <summary>
 27    /// Configures the MultitenantHttpRoutingFeature with custom multitenancy HTTP options.
 28    /// </summary>
 29    /// <param name="configure">The action to configure <see cref="MultitenancyHttpOptions"/>.</param>
 30    /// <returns>The current instance of <see cref="MultitenantHttpRoutingFeature"/> for fluent configuration.</returns>
 31    public MultitenantHttpRoutingFeature WithMultitenancyHttpOptions(Action<MultitenancyHttpOptions> configure)
 32    {
 033        _configureMultitenancyHttpOptions = configure;
 034        return this;
 35    }
 36
 37    public override void Configure()
 38    {
 039        Module.Configure<HttpFeature>(feature =>
 040        {
 041            feature.WithHttpEndpointRoutesProvider<TenantPrefixHttpEndpointRoutesProvider>();
 042            feature.WithHttpEndpointBasePathProvider<TenantPrefixHttpEndpointBasePathProvider>();
 043        });
 044    }
 45
 46    public override void Apply()
 47    {
 48        // Multitenancy HTTP options.
 049        Services.Configure(_configureMultitenancyHttpOptions);
 50
 51        // Tenant resolvers.
 052        Services
 053            .AddScoped<ITenantResolver, RoutePrefixTenantResolver>()
 054            .AddScoped<ITenantResolver, HeaderTenantResolver>()
 055            .AddScoped<ITenantResolver, HostTenantResolver>()
 056            .AddScoped<TenantPrefixHttpEndpointRoutesProvider>();
 057    }
 58}