Dynamic Activity - .NET SDK
Set a Dynamic Activity
How to set a Dynamic Activity using the Temporal .NET SDK
A Dynamic Activity in Temporal is an Activity that is invoked dynamically at runtime if no other Activity with the same name is registered.
An Activity can be made dynamic by setting Dynamic as true on the [Activity] attribute.
You must register the Activity with the Worker before it can be invoked.
Only one Dynamic Activity can be present on a Worker.
The Activity Definition must then accept a single argument of type Temporalio.Converters.IRawValue[].
The PayloadConverter property on the ActivityExecutionContext is used to convert an IRawValue object to the desired type using extension methods in the Temporalio.Converters namespace.
public class MyActivities
{
[Activity(Dynamic = true)]
public string DynamicActivity(IRawValue[] args)
{
var input = ActivityExecutionContext.Current.PayloadConverter.ToValue<MyActivityParams>(args.Single());
return $"{input.Greeting}, {input.Name}!";
}
}