elsa-core/src/common
Sipke Schoorstra a818b5110e
fix(features): support features introduced during Module.Apply() (#7966)
Module.Apply() enumerated _features.Values directly while calling
feature.Apply(). A feature whose Apply() introduces another feature —
Module.Configure<T>() directly, or via a helper such as AddActivity<T>()
which configures WorkflowManagementFeature — mutated that collection
mid-enumeration and threw "Collection was modified; enumeration
operation may not execute", naming nothing about features. Whether it
fired depended on whether the other feature happened to be installed
already, so a module built or did not based on unrelated host config.

The module already treats introduction-during-apply as supported: the
ConfigureFeature loop iterates a snapshot for exactly this reason, and
Configure<T>() has an _isApplying branch that creates, resolves and
configures a feature introduced mid-Apply. Only the final apply loop
missed the same treatment, so make it tolerant rather than diagnose a
constraint the code does not hold.

The apply loop now runs in rounds until no new features appear, each
round topologically sorted so a late feature's dependencies apply before
it. Hosted services are registered in a single pass after that loop,
then moved back to the index the block previously occupied: registering
late is needed so features contributed during Apply() are included and
ordered by priority, while keeping the position matters because features
register hosted services directly from Apply() — WorkflowRuntimeFeature
adds DrainOrchestratorHostedService that way — and module-managed
services must keep starting first, or a priority such as ActivateTenants
at -1 would silently start ordering after them.

Adds Elsa.Features.UnitTests, covering the introduced feature applying,
a three-deep introduction chain, dependency ordering, hosted service
registration and priority ordering for late arrivals, the installed-
feature registry, and no double-apply, plus guards for pre-existing
ordering behaviour.

Closes #7944

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 23:53:07 +02:00
..
Elsa.Api.Common Clarify runtime status permission summary 2026-06-16 23:34:13 +02:00
Elsa.Features fix(features): support features introduced during Module.Apply() (#7966) 2026-08-20 23:53:07 +02:00
Elsa.Mediator [codex] Fix diagnostics live feed regressions (#7548) 2026-05-31 09:40:02 +02:00
Elsa.Testing.Shared feat(bpmn): the BpmnProcess container activity (#7945) 2026-08-14 12:37:35 +02:00
Elsa.Testing.Shared.Component Implement null TenantId for tenant-agnostic entities (#7226) 2026-02-02 10:59:01 +01:00
Elsa.Testing.Shared.Integration [codex] Harden C# expression host-code execution (#7519) 2026-05-21 00:50:25 +02:00
Directory.Build.props Add PackageManifest.props and build properties for package manifest generation 2026-06-08 09:49:12 +02:00