< Summary

Information
Class: Elsa.Common.Multitenancy.TenantScope
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Models/TenantScope.cs
Line coverage
44%
Covered lines: 4
Uncovered lines: 5
Coverable lines: 9
Total lines: 24
Line coverage: 44.4%
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%11100%
get_ServiceScope()100%11100%
get_ServiceProvider()100%11100%
DisposeAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Multitenancy/Models/TenantScope.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2
 3namespace Elsa.Common.Multitenancy;
 4
 5/// <summary>
 6/// Represents a tenant scope, which sets the current tenant for the duration of the scope.
 7/// After the scope is disposed, the original tenant is restored.
 8/// </summary>
 19public class TenantScope(IServiceScope serviceScope, ITenantAccessor tenantAccessor, Tenant? tenant) : IAsyncDisposable
 10{
 111    private readonly IDisposable _tenantContext = tenantAccessor.PushContext(tenant);
 12
 1213    public IServiceScope ServiceScope { get; } = serviceScope;
 1114    public IServiceProvider ServiceProvider => ServiceScope.ServiceProvider;
 15
 16    public async ValueTask DisposeAsync()
 17    {
 018        _tenantContext.Dispose();
 019        if (ServiceScope is IAsyncDisposable asyncDisposable)
 020            await asyncDisposable.DisposeAsync();
 21        else
 022            ServiceScope.Dispose();
 023    }
 24}