Configures Flowchart Execution via DI#7141
Conversation
…logic. - Added `FlowchartExecutionMode` enum to represent execution modes (Default, TokenBased, CounterBased). - Updated flowchart-related integration and unit tests to use the new execution mode. - Removed the global `UseTokenFlow` flag in favor of execution-specific configuration via `RunWorkflowOptions`. - Refactored flowchart-related APIs and test helpers for improved flexibility and modularity.
…rtOptions` and DI. - Introduced extensions for `FlowchartFeature` to simplify configuration. - Added DI support for setting default execution modes. - Refactored flowchart execution logic to prioritize configuration.
There was a problem hiding this comment.
Pull request overview
This PR introduces dependency injection-based configuration for flowchart execution behavior, replacing the previous reliance on a static field (Flowchart.UseTokenFlow) with a more flexible options-based approach. The change enables developers to configure flowchart execution mode (token-based vs counter-based) at three levels: application-wide via DI, per-workflow via options, or as a last resort through the static field.
Key Changes:
- Introduces
FlowchartOptionsclass andFlowchartExecutionModeenum for configuring execution behavior - Adds extension methods for fluent API configuration (
UseFlowchart,WithTokenBasedFlowchart, etc.) - Updates all tests to use the new execution mode configuration instead of mutating static state
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/FlowchartExecutionMode.cs |
New enum defining execution modes (Default, TokenBased, CounterBased) |
src/modules/Elsa.Workflows.Core/Activities/Flowchart/Options/FlowchartOptions.cs |
New options class for configuring default execution mode |
src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/RunWorkflowOptionsExtensions.cs |
Extension methods for configuring execution mode at runtime per workflow |
src/modules/Elsa.Workflows.Core/Activities/Flowchart/Extensions/FlowchartFeatureExtensions.cs |
Extension methods for configuring flowchart feature with execution mode options |
src/modules/Elsa.Workflows.Core/Extensions/ModuleExtensions.cs |
Adds UseFlowchart extension method for module configuration |
src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs |
Implements execution mode resolution with priority: workflow properties > DI options > static field |
src/modules/Elsa.Workflows.Core/Features/FlowchartFeature.cs |
Registers FlowchartOptions in DI container |
src/apps/Elsa.Server.Web/Program.cs |
Demonstrates usage by configuring token-based execution as default |
src/common/Elsa.Testing.Shared.Integration/WorkflowTestFixture.cs |
Adds overloads accepting RunWorkflowOptions for test flexibility |
test/unit/Elsa.Activities.UnitTests/Flow/FlowchartTests.cs |
Updates test to pass execution mode parameter instead of mutating static field |
test/unit/Elsa.Activities.UnitTests/Flow/FlowchartTestHelpers.cs |
Updates helper to accept execution mode parameter and configure via workflow properties |
test/unit/Elsa.Activities.UnitTests/Branching/FlowJoinTests.cs |
Removes IDisposable pattern; uses execution mode parameters instead of static field mutation |
test/integration/Elsa.Workflows.IntegrationTests/Scenarios/FlowchartNextActivity/Tests.cs |
Updates to use WorkflowTestFixture and execution mode options; removes static field mutation |
test/integration/Elsa.Activities.IntegrationTests/Flow/FlowchartTokenBasedTests.cs |
Removes IDisposable pattern; passes FlowchartExecutionMode.TokenBased to all test methods |
test/integration/Elsa.Activities.IntegrationTests/Flow/FlowchartTestHelpers.cs |
Updates helper to accept execution mode and create options accordingly |
test/integration/Elsa.Activities.IntegrationTests/Flow/FlowchartCounterBasedTests.cs |
Removes IDisposable pattern; passes FlowchartExecutionMode.CounterBased to all test methods |
test/integration/Elsa.Activities.IntegrationTests/Branching/FlowJoinTests.cs |
Removes IDisposable pattern; converts boolean flag to execution mode enum |
test/integration/Elsa.Activities.IntegrationTests/Branching/FlowDecisionTests.cs |
Removes IDisposable pattern; uses execution mode options for all tests |
….2 behavior - Changed `DefaultExecutionMode` to `CounterBased`. - Updated `UseTokenFlow` default to `false`.
…owchartExecutionMode.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s/FlowchartFeatureExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…wchartNextActivity/Tests.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s/RunWorkflowOptionsExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nd align with updated Flowchart execution behavior
… enh/flowchart-token-toggle
…lowchartOptions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…um, replacing boolean checks for improved clarity and extensibility.
… enh/flowchart-token-toggle
…ith `FlowchartExecutionMode` enum for clarity and consistency.
…handling and simplify implementation.
j03y-nxxbz
left a comment
There was a problem hiding this comment.
Apart from the 1 comment of Copilot, I have got nothing to add and I would approve if that comment is resolved. Namely:
The UseTokenBased boolean static field in the FlowChart.cs is not used now. As you are already handling the default enum in all the correct places, I would just remove the static property all together.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s/Flowchart.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
j03y-nxxbz
left a comment
There was a problem hiding this comment.
Hereby approved. Nothing to remark
Allows configuration of flowchart execution behavior using
FlowchartOptionsand dependency injection.This provides more flexibility and control over how flowcharts are executed, allowing developers to choose between token-based and counter-based execution modes via configuration.
Sample:
appsettings.json:
{ "Elsa": { "Flowchart": { "DefaultExecutionMode": "TokenBased|CounterBased" } } }This change is