elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.45k stars 1.19k forks source link

Workflow Templates #463

Open sfmskywalker opened 3 years ago

sfmskywalker commented 3 years ago

Workflow Templates allows a given workflow to be placed inside a workflow template, similar to the way a Blazor component template allows a component to have one or more templated properties (render fragments) or a layout Razor page allows sections to be defined.

This enables scenarios where you want to allow for the customization of a part of a workflow that fits neatly within an outer workflow.

This is similar to having a master workflow calling into a child workflow, but inversed: the child workflow declares its parent (template) workflow, and is synthesized at runtime.

Workflow Template

A workflow template is a regular workflow, but marked as being a template so that:

Workflow Sections

When designing a workflow template, a special kind of activity called WorkflowSection becomes available acting as the placeholder for the "child" workflow to be stitched into. Workflow Templates can have multiple, named, sections. Each section's name appears on a child workflow as a starting node (as if the child workflow's root activities are connected to the parent workflows outcomes, where each outcome has the same name as the master workflow's sections).

Workflow Synthesis

Where normally a parent workflow would trigger a child workflow, workflow synthesis works differently: it takes the master workflow and child workflow and stitches them together by replacing the section activities with the root activities from the child workflow, forming a brand new workflow ready for execution.

dwoldo commented 4 months ago

@sfmskywalker In v3 of Elsa, is a Flow an equivalent of this? Where an Activity could either be a series of activities or a call to a another workflow?

sfmskywalker commented 4 months ago

Not exactly; a Flowchart is essentially a set of Activities and a set of Connections between them. It is possible to call other workflows from within a given workflow using DispatchWorkflow and by configuring a given workflow to be "usable as an activity", but it is not quite the same as being able to create a new workflow and selecting a "master" template within which it would execute.