Skip to content

.Net: Simplify the Fluent Syntax for the process framework to improve usability and Reduce Cognitive Overload #10001

Open
@joslat

Description

Proposal

The current process framework API for defining step transitions requires developers to manually handle edges between steps using methods like OnEvent, OnFunctionResult, and SendEventTo. While powerful, this approach introduces verbosity and cognitive overhead when defining sequential processes.

The proposed changes add the following fluent methods:

StartWith:

Specifies the starting step, bound to an input event.
AndThen:

Chains subsequent steps using either:
Default function result events (OnFunctionResult).
Explicit input events (OnEvent).
AndFinally:

Marks the final step and automatically stops the process after execution.
The new methods automatically connect steps and ensure transitions are defined cleanly, without requiring developers to manually link steps using SendEventTo.

Comparison: Old vs New Syntax
Old Syntax (Verbose and Manual):

processBuilder
    .OnInputEvent(ProcessEvents.StartProcess)
    .SendEventTo(new ProcessFunctionTargetBuilder(startStep));

startStep
    .OnFunctionResult()
    .SendEventTo(new ProcessFunctionTargetBuilder(doSomeWorkStep));

doSomeWorkStep
    .OnFunctionResult()
    .SendEventTo(new ProcessFunctionTargetBuilder(doMoreWorkStep));

doMoreWorkStep
    .OnFunctionResult()
    .SendEventTo(new ProcessFunctionTargetBuilder(lastStep));

lastStep
    .OnFunctionResult()
    .StopProcess();

New Syntax (Simplified and Fluent):

processBuilder
    .StartWith<StartStep>(ProcessEvents.StartProcess)
    .AndThen<DoSomeWorkStep>() // Default: OnFunctionResult
    .AndThen<DoMoreWorkStep>(ProcessEvents.CustomEvent) // Explicit event
    .AndFinally<LastStep>(); // Default: OnFunctionResult and stops the process

Benefits

Simplified Syntax:

Transitions between steps are intuitive and fluent, eliminating the need for manual edge linking.
Reduced Cognitive Overload:

Developers no longer need to handle OnEvent and SendEventTo explicitly for each step.
Improved Readability:

The process flow is clean, readable, and aligns with natural language patterns.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions