Skip to content

Commit 592fe62

Browse files
Merge pull request #313358 from hhunter-ms/hh-319306
[Durable][UUF] Class-based approach for orchestrations
2 parents c313079 + f0e3864 commit 592fe62

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

articles/azure-functions/durable/durable-functions-orchestrations.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ This article gives you an overview of orchestrator functions and how they can he
2424

2525
For information about the types of functions available in a Durable Functions app, see [Durable Task programming model](programming-model-overview.md).
2626

27+
> [!TIP]
28+
> If you use C# with the .NET isolated worker model, you can write orchestrations using either a **function-based** approach (static methods with `[Function]` attributes) or a **class-based** approach (classes that inherit from `TaskOrchestrator<TInput, TOutput>`). The class-based approach requires the [Microsoft.DurableTask.Generators](https://www.nuget.org/packages/Microsoft.DurableTask.Generators) source generator package and provides strongly typed invocations. For more information, see [Class-based activities and orchestrations](durable-functions-dotnet-isolated-overview.md#source-generator-and-class-based-activities-and-orchestrations). The C# code examples in this article show both approaches.
29+
2730
::: zone-end
2831

2932
::: zone pivot="durable-task-sdks"
@@ -116,6 +119,36 @@ public static async Task<List<string>> Run(
116119

117120
<br>
118121

122+
<details>
123+
<summary><b>Class-based model (isolated worker)</b></summary>
124+
125+
The class-based approach uses a source generator and requires the [Microsoft.DurableTask.Generators](https://www.nuget.org/packages/Microsoft.DurableTask.Generators) NuGet package.
126+
127+
```csharp
128+
using Microsoft.DurableTask;
129+
130+
[DurableTask]
131+
public class HelloCities : TaskOrchestrator<object?, List<string>>
132+
{
133+
public override async Task<List<string>> RunAsync(
134+
TaskOrchestrationContext context, object? input)
135+
{
136+
var outputs = new List<string>();
137+
138+
outputs.Add(await context.CallActivityAsync<string>("SayHello", "Tokyo"));
139+
outputs.Add(await context.CallActivityAsync<string>("SayHello", "Seattle"));
140+
outputs.Add(await context.CallActivityAsync<string>("SayHello", "London"));
141+
142+
// Return ["Hello Tokyo!", "Hello Seattle!", "Hello London!"].
143+
return outputs;
144+
}
145+
}
146+
```
147+
148+
</details>
149+
150+
<br>
151+
119152
<details>
120153
<summary><b>In-process model</b></summary>
121154

0 commit comments

Comments
 (0)