| | | 1 | | using CShells.Features; |
| | | 2 | | using CShells.Lifecycle; |
| | | 3 | | using Elsa.Common.Multitenancy; |
| | | 4 | | using Elsa.Common.Multitenancy.EventHandlers; |
| | | 5 | | using Elsa.Common.Multitenancy.HostedServices; |
| | | 6 | | using Elsa.Common.RecurringTasks; |
| | | 7 | | using Elsa.Common.ShellHandlers; |
| | | 8 | | using Elsa.Extensions; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Common.ShellFeatures; |
| | | 12 | | |
| | | 13 | | [ShellFeature( |
| | | 14 | | "Multitenancy", |
| | | 15 | | DisplayName = "Multitenancy", |
| | | 16 | | Description = "Provides tenant resolution, tenant scopes, and tenant lifecycle services")] |
| | | 17 | | public class MultitenancyFeature : IShellFeature |
| | | 18 | | { |
| | 0 | 19 | | private readonly Func<IServiceProvider, ITenantsProvider> _tenantsProviderFactory = sp => sp.GetRequiredService<Defa |
| | | 20 | | |
| | | 21 | | public void ConfigureServices(IServiceCollection services) |
| | | 22 | | { |
| | 0 | 23 | | services |
| | 0 | 24 | | .AddSingleton<ITenantScopeFactory, DefaultTenantScopeFactory>() |
| | 0 | 25 | | .AddSingleton<ITenantAccessor, DefaultTenantAccessor>() |
| | 0 | 26 | | .AddSingleton<ITenantFinder, DefaultTenantFinder>() |
| | 0 | 27 | | .AddSingleton<ITenantService, DefaultTenantService>() |
| | 0 | 28 | | |
| | 0 | 29 | | // Coordinate tenant task lifecycle separately from the tenant event pipeline. |
| | 0 | 30 | | .AddSingleton<TenantTaskLifecycleCoordinator>() |
| | 0 | 31 | | .AddSingleton<TenantTaskLifecycleEventHandler>() |
| | 0 | 32 | | .AddSingleton<ITenantActivatedEvent>(sp => sp.GetRequiredService<TenantTaskLifecycleEventHandler>()) |
| | 0 | 33 | | .AddSingleton<ITenantDeactivatedEvent>(sp => sp.GetRequiredService<TenantTaskLifecycleEventHandler>()) |
| | 0 | 34 | | |
| | 0 | 35 | | .AddSingleton<RecurringTaskScheduleManager>() |
| | 0 | 36 | | .AddSingleton<TenantEventsManager>() |
| | 0 | 37 | | .AddScoped<DefaultTenantsProvider>() |
| | 0 | 38 | | .AddScoped<DefaultTenantResolver>() |
| | 0 | 39 | | .AddScoped<ITenantBackgroundWorkQueue, TenantBackgroundWorkQueue>() |
| | 0 | 40 | | .AddScoped<ITaskExecutor, TaskExecutor>() |
| | 0 | 41 | | .AddScoped<IBackgroundTaskStarter, TaskExecutor>() |
| | 0 | 42 | | .AddBackgroundTask<TenantBackgroundWorkQueueWorker>() |
| | 0 | 43 | | .AddScoped(_tenantsProviderFactory) |
| | 0 | 44 | | |
| | 0 | 45 | | // Transient per CShells 0.0.15 convention — the registry resolves IEnumerable<IShellInitializer> and |
| | 0 | 46 | | // IEnumerable<IDrainHandler> on demand from the shell's IServiceProvider during activation/draining. |
| | 0 | 47 | | .AddTransient<IShellInitializer, ActivateShellTenants>() |
| | 0 | 48 | | .AddTransient<IDrainHandler, ActivateShellTenants>() |
| | 0 | 49 | | ; |
| | 0 | 50 | | } |
| | | 51 | | } |