Reorder tenant services initialization for proper execution.

Ensure `RunStartupTasks` is added before background and recurring tasks as order is critical for correct startup and tenant activation behavior. This prevents potential misalignment in task execution during tenant lifecycle events.

Fixes #6269
This commit is contained in:
Sipke Schoorstra 2025-01-15 18:40:24 +01:00
parent 3966824d29
commit 0b5f580b0d

View file

@ -40,6 +40,9 @@ public class MultitenancyFeature(IModule module) : FeatureBase(module)
.AddSingleton<ITenantFinder, DefaultTenantFinder>()
.AddSingleton<ITenantService, DefaultTenantService>()
// Order is important: Startup task first, then background and recurring tasks.
.AddSingleton<ITenantActivatedEvent, RunStartupTasks>()
.AddSingleton<RunBackgroundTasks>()
.AddSingleton<ITenantActivatedEvent>(sp => sp.GetRequiredService<RunBackgroundTasks>())
.AddSingleton<ITenantDeactivatedEvent>(sp => sp.GetRequiredService<RunBackgroundTasks>())
@ -48,7 +51,6 @@ public class MultitenancyFeature(IModule module) : FeatureBase(module)
.AddSingleton<ITenantActivatedEvent>(sp => sp.GetRequiredService<StartRecurringTasks>())
.AddSingleton<ITenantDeactivatedEvent>(sp => sp.GetRequiredService<StartRecurringTasks>())
.AddSingleton<ITenantActivatedEvent, RunStartupTasks>()
.AddSingleton<RecurringTaskScheduleManager>()
.AddSingleton<TenantEventsManager>()
.AddScoped<DefaultTenantsProvider>()