Skip to content

Configures Flowchart Execution via DI#7141

Merged
sfmskywalker merged 19 commits into
develop/3.6.0from
enh/flowchart-token-toggle
Dec 15, 2025
Merged

Configures Flowchart Execution via DI#7141
sfmskywalker merged 19 commits into
develop/3.6.0from
enh/flowchart-token-toggle

Conversation

@sfmskywalker

@sfmskywalker sfmskywalker commented Dec 11, 2025

Copy link
Copy Markdown
Member

Allows configuration of flowchart execution behavior using FlowchartOptions and 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:

elsa.UseFlowchart(flowchart => 
{
   // Use counter based algorithm from 3.5.2:
   flowchart.UseCounterBasedExecution();

   // Or, use token based algorithm introduced with 3.6.0:
   flowchart.UseTokenBasedExecution();

   // Different syntax possible also in case the setting comes from e.g. config:
   flowchart.UseExecution(FlowchartExecutionMode.TokenBased);
   flowchart.UseExecution(FlowchartExecutionMode.CounterBased);
});

// Alternatively, bind the options directly against configuration:
services.Configure<FlowchartOptions>(options => configuration.GetSection("Elsa:Flowchart").Bind(options));

appsettings.json:

{
   "Elsa": {
      "Flowchart": {
         "DefaultExecutionMode": "TokenBased|CounterBased"
      }
   }
}

This change is Reviewable

…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.
Copilot AI review requested due to automatic review settings December 11, 2025 17:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 FlowchartOptions class and FlowchartExecutionMode enum 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`.
@sfmskywalker sfmskywalker requested a review from Copilot December 11, 2025 18:17
…owchartExecutionMode.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
sfmskywalker and others added 4 commits December 11, 2025 19:17
…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Comment thread src/modules/Elsa.Workflows.Core/Activities/Flowchart/Options/FlowchartOptions.cs Outdated
Comment thread src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 3 comments.

Comment thread src/modules/Elsa.Workflows.Core/Activities/Flowchart/Activities/Flowchart.cs Outdated
Comment thread src/common/Elsa.Testing.Shared.Integration/WorkflowTestFixture.cs Outdated

@j03y-nxxbz j03y-nxxbz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

sfmskywalker and others added 2 commits December 12, 2025 22:28
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 j03y-nxxbz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hereby approved. Nothing to remark

@sfmskywalker sfmskywalker merged commit 4bbdd6f into develop/3.6.0 Dec 15, 2025
8 checks passed
@sfmskywalker sfmskywalker deleted the enh/flowchart-token-toggle branch December 15, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants