OrchardCore
OrchardCore copied to clipboard
Tenant activation event should be raised after the pipeline has been build
When using IModularTenantEvents, the ActivatedAsync() method is called before the tenant pipeline has been build. This makes it impossible to use the event for initializing modules that rely on the pipeline being initialized.
Should we need more events?
Also, could you describe your scenario?
The scenario was to workaround #2268 and I was just expecting the tenant activated event to be raised after the pipeline has been build, similar to what the IApplicationLifetime is doing.
The tenant IModularTenantEvents are currently invoked this way on start up:
var tenantEvents = activatingScope.ServiceProvider.GetServices<IModularTenantEvents>();
foreach (var tenantEvent in tenantEvents)
{
await tenantEvent.ActivatingAsync();
}
httpContext.Items["BuildPipeline"] = true;
foreach (var tenantEvent in tenantEvents.Reverse())
{
await tenantEvent.ActivatedAsync();
}
The "BuildPipeline" flag notifies another middleware to rebuid the pipeline.
I don't think more events are required. If the behavior should stay this way, I would instead suggest to remove one of the two events (just keep the activated event).
Just for infos we also call .ActivatedAsync()
in RecipeExecutor.cs
in ExecuteStepAsync()
. During a setup this is not called in the context of a request. So maybe we would need another distinct event to say that the tenant pipeline has been built, meaning that it has also been activated previously.