diff --git a/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs b/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs
index fd5608325..21cdef3ff 100644
--- a/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs
+++ b/src/modules/Elsa.Workflows.Core/Builders/WorkflowBuilder.cs
@@ -88,6 +88,14 @@ public class WorkflowBuilder(IActivityVisitor activityVisitor, IIdentityGraphSer
return variable;
}
+ ///
+ public Variable WithVariable(string name)
+ {
+ var variable = new Variable(name, default!);
+ Variables.Add(variable);
+ return variable;
+ }
+
///
public Variable WithVariable(string name, T value)
{
@@ -298,4 +306,4 @@ public class WorkflowBuilder(IActivityVisitor activityVisitor, IIdentityGraphSer
await workflowDefinition.BuildAsync(this, cancellationToken);
return await BuildWorkflowAsync(cancellationToken);
}
-}
\ No newline at end of file
+}
diff --git a/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs b/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs
index 3d7c3cb8a..971291013 100644
--- a/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs
+++ b/src/modules/Elsa.Workflows.Core/Contracts/IWorkflowBuilder.cs
@@ -115,6 +115,11 @@ public interface IWorkflowBuilder
[Obsolete("Use the overload that takes a name instead. This overload will be removed in a future version.")]
Variable WithVariable();
+ ///
+ /// A fluent method for adding a variable to .
+ ///
+ Variable WithVariable(string name);
+
///
/// A fluent method for adding a variable to .
///
@@ -220,4 +225,4 @@ public interface IWorkflowBuilder
/// Creates a new instance using the specified definition.
///
Task BuildWorkflowAsync(IWorkflow workflowDefinition, CancellationToken cancellationToken = default);
-}
\ No newline at end of file
+}
diff --git a/test/integration/Elsa.Workflows.IntegrationTests/Serialization/VariableExpressions/Workflows.cs b/test/integration/Elsa.Workflows.IntegrationTests/Serialization/VariableExpressions/Workflows.cs
index 2d6cc93e0..e36d07407 100644
--- a/test/integration/Elsa.Workflows.IntegrationTests/Serialization/VariableExpressions/Workflows.cs
+++ b/test/integration/Elsa.Workflows.IntegrationTests/Serialization/VariableExpressions/Workflows.cs
@@ -7,7 +7,7 @@ class SampleWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder workflow)
{
- var variable1 = workflow.WithVariable("Some variable");
+ var variable1 = workflow.WithVariable("Some variable");
var variable2 = workflow.WithVariable(42);
var literal1 = new Literal("Some literal");
var literal2 = new Literal(84);
@@ -27,4 +27,4 @@ class SampleWorkflow : WorkflowBase
}
};
}
-}
\ No newline at end of file
+}