elsa-workflows / elsa-workflows/elsa-core

Add support for Workflow Model

Open
#596 9 comments 6 reactions 0 assignees View on GitHub
enhancement prio low triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

Currently, a workflow can define variables to store and retrieve state using `SetVariable` and `GetVariable` activities and methods. This works fine, but the syntax can become a bit cumbersome.

What we could have in addition is the notion of a "model" (or data or state) that is just like a variable, but available through a new strongly-typed property called `Model`. This would be somewhat analogous to the `Model` property on a Razor view.

This allows the user to define workflows that look very similar to the way it's done in [Workflow Core](https://github.com/danielgerlag/workflow-core#sample-use-cases):

```csharp
public class MyModel
{
public string Email { get; set; }
public string Password { get; set; }
public string UserId { get; set; }
}

public class MyWorkflow : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{
builder
.StartWith()
.With(activity => activity.Email, model=> model.Email)
.With(activity => activity.Password, model => model.Password)
.Then(context => context.Model.UserId = context.Input())
.Then()
.With(activity => activity.Email, model => model.Email)
.With(activity => activity.UserId, model => model.UserId)
.Then()
.With(activity => activity.UserId, model => model.UserId)
.Then()
.With(activity => activity.UserId, model => model.UserId);
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.