< Summary

Information
Class: Elsa.Tenants.Mediator.Middleware.TenantPropagatingMiddleware
Assembly: Elsa.Tenants
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Mediator/Middleware/TenantPropagatingMiddleware.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 28
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%
InvokeAsync()0%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Tenants/Mediator/Middleware/TenantPropagatingMiddleware.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Mediator.Middleware.Command;
 3using Elsa.Mediator.Middleware.Command.Contracts;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Tenants.Mediator.Middleware;
 7
 8/// <summary>
 9/// Middleware that ensures tenant context is propagated through the request pipeline.
 10/// </summary>
 11[UsedImplicitly]
 012public class TenantPropagatingMiddleware(CommandMiddlewareDelegate next, ITenantScopeFactory tenantScopeFactory, ITenant
 13{
 14    /// <inheritdoc />
 15    public async ValueTask InvokeAsync(CommandContext context)
 16    {
 017        if (context.Headers.TryGetValue(TenantHeaders.TenantIdKey, out var tenantIdVal))
 18        {
 019            var tenantId = (string)tenantIdVal;
 020            var tenant = await tenantService.FindAsync(tenantId);
 021            await using var tenantScope = tenantScopeFactory.CreateScope(tenant);
 022            await next(context);
 023            return;
 024        }
 25
 026        await next(context);
 027    }
 28}