elsa-core/src/modules/Elsa.Common/Features/MultitenancyFeature.cs
Sipke Schoorstra 8e301d4e1e
[codex] Scope console logs to workflow instances (#7535)
* Avoid null endpoint DTO metadata in tests

* Enforce console logs hub read permission

* Remove unused console logs hub import

* Support mapped endpoint metadata in auth tests

* Reduce console log capture throughput impact

* Address Copilot console logs review

* Refactor task scheduling to support tenant-level background work and enhance logging functionality.

* Introduce ConsoleStreamHook for stdout/stderr tee and enhance logging validation. Adjust test cases and startup warnings for distributed lock provider usage.

* Refactor console logging pipeline with capture optimization and new ConsoleLogsHost; update tests accordingly.

* Add Ansi SGR parser for console logs and associated unit tests

* Remove ANSI color renderings and parsers; integrate ConsoleLogScopeAccessor for improved logging context with workflow instance ID support.

* Address console logs code quality feedback

* Address PR review feedback

* Preserve console logs extension points

* Stabilize console logs host lifecycle

* Address final automated review comments

* Tighten console log capture shutdown

* Address console log review feedback

* Address follow-up review feedback

* Cover final review feedback

* Avoid recursive console provider initialization

* Guard console host lease shutdown

* Preserve console log scope and provider lifetime

* Correlate console log scope fallback

* Tighten console scope correlation

* Expose host services during provider construction

* Redact ANSI-normalized console lines
2026-05-25 11:49:51 +02:00

61 lines
2.5 KiB
C#

using Elsa.Common.Multitenancy;
using Elsa.Common.Multitenancy.EventHandlers;
using Elsa.Common.Multitenancy.HostedServices;
using Elsa.Common.RecurringTasks;
using Elsa.Extensions;
using Elsa.Features.Abstractions;
using Elsa.Features.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Elsa.Common.Features;
public class MultitenancyFeature(IModule module) : FeatureBase(module)
{
private Func<IServiceProvider, ITenantsProvider> _tenantsProviderFactory = sp => sp.GetRequiredService<DefaultTenantsProvider>();
public MultitenancyFeature UseTenantsProvider<TTenantsProvider>() where TTenantsProvider : class, ITenantsProvider
{
Services.TryAddScoped<TTenantsProvider>();
return UseTenantsProvider(sp => sp.GetRequiredService<TTenantsProvider>());
}
public MultitenancyFeature UseTenantsProvider(Func<IServiceProvider, ITenantsProvider> tenantsProviderFactory)
{
_tenantsProviderFactory = tenantsProviderFactory;
return this;
}
public override void ConfigureHostedServices()
{
Module
.ConfigureHostedService<ActivateTenants>(-1)
;
}
public override void Apply()
{
Services
.AddSingleton<ITenantScopeFactory, DefaultTenantScopeFactory>()
.AddSingleton<ITenantAccessor, DefaultTenantAccessor>()
.AddSingleton<ITenantFinder, DefaultTenantFinder>()
.AddSingleton<ITenantService, DefaultTenantService>()
// Coordinate tenant task lifecycle separately from the tenant event pipeline.
.AddSingleton<TenantTaskLifecycleCoordinator>()
.AddSingleton<TenantTaskLifecycleEventHandler>()
.AddSingleton<ITenantActivatedEvent>(sp => sp.GetRequiredService<TenantTaskLifecycleEventHandler>())
.AddSingleton<ITenantDeactivatedEvent>(sp => sp.GetRequiredService<TenantTaskLifecycleEventHandler>())
.AddSingleton<RecurringTaskScheduleManager>()
.AddSingleton<TenantEventsManager>()
.AddScoped<DefaultTenantsProvider>()
.AddScoped<DefaultTenantResolver>()
.AddScoped<ITenantBackgroundWorkQueue, TenantBackgroundWorkQueue>()
.AddScoped<ITaskExecutor, TaskExecutor>()
.AddScoped<IBackgroundTaskStarter, TaskExecutor>()
.AddBackgroundTask<TenantBackgroundWorkQueueWorker>()
.AddScoped(_tenantsProviderFactory);
}
}