< Summary

Information
Class: Elsa.Tenants.AspNetCore.HostTenantResolver
Assembly: Elsa.Tenants.AspNetCore
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants.AspNetCore/Resolvers/HostTenantResolver.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 30
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%
Resolve(...)0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants.AspNetCore/Resolvers/HostTenantResolver.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Microsoft.AspNetCore.Http;
 3
 4namespace Elsa.Tenants.AspNetCore;
 5
 6/// <summary>
 7/// Resolves the tenant based on the host in the request.
 8/// </summary>
 09public class HostTenantResolver(IHttpContextAccessor httpContextAccessor) : TenantResolverBase
 10{
 11    protected override TenantResolverResult Resolve(TenantResolverContext context)
 12    {
 013        var httpContext = httpContextAccessor.HttpContext;
 14
 015        if (httpContext == null)
 016            return Unresolved();
 17
 018        var host = httpContext.Request.Host;
 019        var inboundHostAndPort = host.Host + (host.Port.HasValue ? ":" + host.Port : null);
 020        var tenant = context.FindTenant(x =>
 021        {
 022            var tenantHost = x.GetHost();
 023            return tenantHost == inboundHostAndPort;
 024        });
 25
 026        var tenantId = tenant?.Id;
 27
 028        return AutoResolve(tenantId);
 29    }
 30}