elsa-core
elsa-core copied to clipboard
Support Programmatic Definition of Dynamically Provided Activities
Currently, Elsa Workflows supports dynamic activity providers, enabling activities to be dynamically added to the system and utilized within the designer. However, there is a gap in functionality when it comes to using these dynamically provided activities within programmatic workflows. Unlike activities defined as .NET classes—which can be instantiated directly—the API lacks a means to incorporate dynamically provided activities into workflow classes programmatically.
Proposed Enhancement
To bridge this gap, it's proposed to extend the workflow builder API to facilitate the definition and utilization of dynamically provided activities in programmatic workflows. This enhancement will allow for more flexible workflow definitions that can adapt to changing requirements without necessitating a recompile of the workflow classes.
Example API Proposal
The following is a proposed API enhancement that illustrates how a developer might define a workflow programmatically using a dynamically provided activity:
public class OrderWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
var orderId = builder.WithVariable<string>("OrderId", null!);
var order = builder.WithVariable<Order>("Order", null);
builder.Root = new Sequence
{
Activities =
{
new ActivityInstance("Acme.DownloadOrder")
{
Inputs = new
{
OrderId = new Input<string>(context => orderId.Get(context)!)
},
Outputs = new
{
Order = new Output(order)
}
},
}
};
}
}
In the example above, "Acme.DownloadOrder"
represents an activity that is dynamically provided. This API would significantly enhance the flexibility and power of Elsa Workflows by enabling developers to programmatically define workflows that include both statically and dynamically provided activities.
Benefit
Implementing this feature would make Elsa Workflows more versatile, supporting a wider range of workflow scenarios and integration patterns. It would empower developers to build more dynamic, adaptable workflow solutions.
To address the proposed enhancement for incorporating dynamically provided activities into programmatic workflows in Elsa Workflows, it's important to note that Elsa already supports a mechanism for defining workflows programmatically and dynamically. However, the current documentation and examples primarily illustrate the use of statically defined .NET classes.
The proposed API enhancement suggests extending the workflow builder API to allow for the inclusion of dynamically provided activities within programmatic workflows. This would indeed increase the flexibility of Elsa Workflows, enabling developers to define workflows that can adapt to changes without the need for recompilation.
As of my knowledge cutoff date in early 2023, the Elsa Workflows documentation and GitHub discussions indicate that Elsa 3 supports dynamic workflows and activities. For instance, the IWorkflowProvider
interface allows for the dynamic provision of workflows, which can be read from JSON and mapped into Elsa workflows programmatically.
To implement the proposed enhancement, the Elsa team would need to extend the existing workflow builder API to support the instantiation and configuration of dynamically provided activities within the programmatic workflow definitions. This could involve creating a new API method or extending existing ones to accept activity identifiers (e.g., "Acme.DownloadOrder"
) and to configure their inputs and outputs dynamically.
It's also worth noting that Elsa Workflows is an open-source project, and contributions from the community are welcomed. If this feature is not yet available, you could consider contributing to the project by implementing the proposed API changes and submitting a pull request for review by the Elsa team.
For the most up-to-date information on this feature and to check if it has been implemented after my knowledge cutoff date, I recommend checking the official Elsa Workflows documentation, GitHub repository, and discussions for any updates or new releases that may address this enhancement.