Class-based syntax allows you to define orchestrators and activities as classes instead of functions. This relies on the Microsoft.DurableTask.Generators package (currently in preview).
When using this syntax, source generators create type-safe extension methods on the client and context objects, allowing you to call activities and orchestrations without manually specifying names or return types.
Note: This feature is in preview and may undergo significant changes. It is recommended to use function-syntax for production workloads.
[DurableTask(nameof(HelloCitiesTyped))]
public class HelloCitiesTyped : TaskOrchestrator<string?, string>
{
public async override Task<string> RunAsync(TaskOrchestrationContext context, string? input)
{
string result = "";
result += await context.CallSayHelloTypedAsync("Tokyo") + " ";
result += await context.CallSayHelloTypedAsync("London") + " ";
result += await context.CallSayHelloTypedAsync("Seattle");
return result;
}
}
[DurableTask(nameof(SayHelloTyped))]
public class SayHelloTyped : TaskActivity<string, string>
{
public override Task<string> RunAsync(TaskActivityContext context, string cityName)
{
return Task.FromResult($"Hello, {cityName}!");
}
}