diff --git a/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs b/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs index 7975f3bf9..1be3bf461 100644 --- a/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs +++ b/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs @@ -112,7 +112,60 @@ public class WorkflowBuilder : IWorkflowBuilder /// public IWorkflowBuilder WithVariables(params Variable[] variables) { - foreach (var variable in variables) Variables.Add(variable); + foreach (var variable in variables) + Variables.Add(variable); + return this; + } + + /// + public InputDefinition WithInput(string name, string? description = default) + { + return WithInput(inputDefinition => + { + inputDefinition.Name = name; + + if (description != null) + inputDefinition.Description = description; + }); + } + + /// + public InputDefinition WithInput(string name, Type type, string? description = default) + { + return WithInput(inputDefinition => + { + inputDefinition.Name = name; + inputDefinition.Type = type; + + if (description != null) + inputDefinition.Description = description; + }); + } + + /// + public InputDefinition WithInput(string name, Type type, Action? setup = default) + { + return WithInput(inputDefinition => + { + inputDefinition.Name = name; + inputDefinition.Type = type; + setup?.Invoke(inputDefinition); + }); + } + + /// + public InputDefinition WithInput(Action setup) + { + var inputDefinition = new InputDefinition(); + setup(inputDefinition); + Inputs.Add(inputDefinition); + return inputDefinition; + } + + /// + public IWorkflowBuilder WithInput(InputDefinition inputDefinition) + { + Inputs.Add(inputDefinition); return this; } diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs b/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs index 30034e78f..ac8ac58ec 100644 --- a/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs +++ b/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs @@ -109,6 +109,31 @@ public interface IWorkflowBuilder /// A fluent method for adding a variable to . /// IWorkflowBuilder WithVariables(params Variable[] variables); + + /// + /// A fluent method for adding an input to . + /// + InputDefinition WithInput(string name, string? description = default); + + /// + /// A fluent method for adding an input to . + /// + InputDefinition WithInput(string name, Type type, string? description = default); + + /// + /// A fluent method for adding an input to . + /// + InputDefinition WithInput(string name, Type type, Action? setup = default); + + /// + /// A fluent method for adding an input to . + /// + InputDefinition WithInput(Action setup); + + /// + /// A fluent method for adding an input to . + /// + IWorkflowBuilder WithInput(InputDefinition inputDefinition); /// /// A fluent method for adding a property to . diff --git a/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs index 385d5477a..ca56cc449 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/ExpressionExecutionContextExtensions.cs @@ -338,6 +338,18 @@ public static class ExpressionExecutionContextExtensions } } + /// + /// Returns the input value associated with the specified in the given . + /// + /// The type of the input value. + /// The containing the input. + /// The specifying the input to retrieve. + /// The input value associated with the specified in the . + public static T? GetInput(this ExpressionExecutionContext context, InputDefinition inputDefinition) + { + return context.GetInput(inputDefinition.Name); + } + /// /// Returns the value of the specified input. ///