Skip to main content

Dynamic Workflow - .NET SDK

Set a Dynamic Workflow

How to set a Dynamic Workflow using the Temporal .NET SDK

A Dynamic Workflow in Temporal is a Workflow that is invoked dynamically at runtime if no other Workflow with the same name is registered. A Workflow can be made dynamic by setting Dynamic as true on the [Workflow] attribute. You must register the Workflow with the Worker before it can be invoked. Only one Dynamic Workflow can be present on a Worker.

The Workflow Definition must then accept a single argument of type Temporalio.Converters.IRawValue[]. The Workflow.PayloadConverter property is used to convert an IRawValue object to the desired type using extension methods in the Temporalio.Converters namespace.

[Workflow(Dynamic = true)]
public class DynamicWorkflow
{
[WorkflowRun]
public async Task<string> RunAsync(IRawValue[] args)
{
var name = Workflow.PayloadConverter.ToValue<string>(args.Single());
var param = MyActivityParams("Hello", name);
return await Workflow.ExecuteActivityAsync(
(MyActivities a) => a.MyActivity(param),
new() { StartToCloseTimeout = TimeSpan.FromMinutes(5) });
}
}