Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joslat opened this issue Dec 17, 2024 · 1 comment
Labels
enhancement .NET Issue or Pull requests regarding .NET code processes

Comments

@joslat
Copy link
Contributor

joslat commented Dec 17, 2024

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.

@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Dec 17, 2024
@github-actions github-actions bot changed the title .NET: Simplify the Fluent Syntax for the process framework to improve usability and Reduce Cognitive Overload .Net: Simplify the Fluent Syntax for the process framework to improve usability and Reduce Cognitive Overload Dec 17, 2024
@evchaki
Copy link
Contributor

evchaki commented Dec 17, 2024

@alliscode and @esttenorio can you take a look at this and the PR when you get back.

@sphenry sphenry removed the triage label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement .NET Issue or Pull requests regarding .NET code processes
Projects
None yet
Development

No branches or pull requests

4 participants