< Summary

Information
Class: Elsa.Common.ShellFeatures.MultitenancyFeature
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/ShellFeatures/MultitenancyFeature.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 51
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%
ConfigureServices(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/ShellFeatures/MultitenancyFeature.cs

#LineLine coverage
 1using CShells.Features;
 2using CShells.Lifecycle;
 3using Elsa.Common.Multitenancy;
 4using Elsa.Common.Multitenancy.EventHandlers;
 5using Elsa.Common.Multitenancy.HostedServices;
 6using Elsa.Common.RecurringTasks;
 7using Elsa.Common.ShellHandlers;
 8using Elsa.Extensions;
 9using Microsoft.Extensions.DependencyInjection;
 10
 11namespace Elsa.Common.ShellFeatures;
 12
 13[ShellFeature(
 14    "Multitenancy",
 15    DisplayName = "Multitenancy",
 16    Description = "Provides tenant resolution, tenant scopes, and tenant lifecycle services")]
 17public class MultitenancyFeature : IShellFeature
 18{
 019    private readonly Func<IServiceProvider, ITenantsProvider> _tenantsProviderFactory = sp => sp.GetRequiredService<Defa
 20
 21    public void ConfigureServices(IServiceCollection services)
 22    {
 023        services
 024            .AddSingleton<ITenantScopeFactory, DefaultTenantScopeFactory>()
 025            .AddSingleton<ITenantAccessor, DefaultTenantAccessor>()
 026            .AddSingleton<ITenantFinder, DefaultTenantFinder>()
 027            .AddSingleton<ITenantService, DefaultTenantService>()
 028
 029            // Coordinate tenant task lifecycle separately from the tenant event pipeline.
 030            .AddSingleton<TenantTaskLifecycleCoordinator>()
 031            .AddSingleton<TenantTaskLifecycleEventHandler>()
 032            .AddSingleton<ITenantActivatedEvent>(sp => sp.GetRequiredService<TenantTaskLifecycleEventHandler>())
 033            .AddSingleton<ITenantDeactivatedEvent>(sp => sp.GetRequiredService<TenantTaskLifecycleEventHandler>())
 034
 035            .AddSingleton<RecurringTaskScheduleManager>()
 036            .AddSingleton<TenantEventsManager>()
 037            .AddScoped<DefaultTenantsProvider>()
 038            .AddScoped<DefaultTenantResolver>()
 039            .AddScoped<ITenantBackgroundWorkQueue, TenantBackgroundWorkQueue>()
 040            .AddScoped<ITaskExecutor, TaskExecutor>()
 041            .AddScoped<IBackgroundTaskStarter, TaskExecutor>()
 042            .AddBackgroundTask<TenantBackgroundWorkQueueWorker>()
 043            .AddScoped(_tenantsProviderFactory)
 044
 045            // Transient per CShells 0.0.15 convention — the registry resolves IEnumerable<IShellInitializer> and
 046            // IEnumerable<IDrainHandler> on demand from the shell's IServiceProvider during activation/draining.
 047            .AddTransient<IShellInitializer, ActivateShellTenants>()
 048            .AddTransient<IDrainHandler, ActivateShellTenants>()
 049            ;
 050    }
 51}