Skip to content

marcduiker/durable-functions-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Durable Functions Snippets

Visual Studio, Code & Rider C# code snippets for Durable Functions (v2.x).

Create orchestration client function - funccl

Type funccl inside a new class followed by one or two [TAB]s depending on your IDE and it results in:

[FunctionName(nameof(OrchestrationClientClassName))]
public async Task Run(
    [TriggerAttribute] ParameterType parameterName,
    [DurableClient] IDurableClient client,
    ILogger logger)
{

    // TODO
    // object input = ;
    // string instanceId = await client.StartNewAsync(
    //    nameof(OrchestrationClassName), 
    //    input);
}

Create orchestrator function - funcor

Type funcor inside a new class followed by one or two [TAB]s depending on your IDE and it results in:

[FunctionName(nameof(OrchestratorClassName))]
public async Task Run(
    [OrchestrationTrigger] IDurableOrchestrationContext context,
    ILogger logger)
{

    // Since the orchestrator code is being replayed many times
    // don't depend on non-deterministic behavior or blocking calls such as:
    // - DateTime.Now (use context.CurrentUtcDateTime instead)
    // - Guid.NewGuid (use context.NewGuid instead)
    // - System.IO
    // - Thread.Sleep/Task.Delay (use context.CreateTimer instead)
    //
    // More info: https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints

    // TODO
    // var input = context.GetInput<T>();
    // var activityResult = await context.CallActivityAsync<string>(
    //    nameof(ActivityClassName),
    //    input));
}

Create activity function - funcac

Type funcac inside a new class followed by one or two [TAB]s depending on your IDE and it results in:

[FunctionName(nameof(ActivityClassName))]
public async Task<OutputType> Run(
    [ActivityTrigger] InputType input,
    ILogger logger)
{

    // TODO
}

How to install

Microsoft Visual Studio

Download the snippet file locally and import it in Visual Studio by following these instructions.

Microsoft Visual Studio Code

Until I've managed to create a proper extension you can copy & paste the content from this file into your own User Snippets as is documented here.

Jetbrains Rider

Download the DotSettings file locally and import it in Rider by following these instructions.

Dependencies

It works best if you are working in a Function App project with a reference to the DurableTask nuget package. So these references should be available:

  • Microsft.Azure.WebJobs.Extensions.DurableTask
  • Microsft.Azure.WebJobs.Extensions.Storage (only if you plan to use the default QueueTrigger in the orchestration client snippet).
  • Microsoft.NET.Sdk.Functions

About

VS & Rider code snippets/templates for orchestration client, orchestrator and activity functions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published