DurableTask.TypedProxy 2.2.2

dotnet add package DurableTask.TypedProxy --version 2.2.2                
NuGet\Install-Package DurableTask.TypedProxy -Version 2.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DurableTask.TypedProxy" Version="2.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DurableTask.TypedProxy --version 2.2.2                
#r "nuget: DurableTask.TypedProxy, 2.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DurableTask.TypedProxy as a Cake Addin
#addin nuget:?package=DurableTask.TypedProxy&version=2.2.2

// Install DurableTask.TypedProxy as a Cake Tool
#tool nuget:?package=DurableTask.TypedProxy&version=2.2.2                

Type-safe activity helper for Durable Functions

Build Downloads NuGet License

Basic usage

1. Implement the activity

// Contract for activity
public interface IHelloActivity
{
    // The return type must be Task or Task <T>
    Task<string> SayHello(string name);
}

// Implementation of activity
public class HelloActivity : IHelloActivity
{
    [FunctionName(nameof(SayHello))]
    public Task<string> SayHello([ActivityTrigger] string name)
    {
        return Task.FromResult($"Hello {name}!");
    }
}

2. Create type-safe proxy and called methods

public class Function1
{
    [FunctionName("Function1")]
    public async Task<List<string>> RunOrchestrator(
        [OrchestrationTrigger] DurableOrchestrationContext context)
    {
        var outputs = new List<string>();

        // Create type-safe activity proxy with interface
        var proxy = context.CreateActivityProxy<IHelloActivity>();

        // Replace "hello" with the name of your Durable Activity Function.
        outputs.Add(await proxy.SayHello("Tokyo"));
        outputs.Add(await proxy.SayHello("Seattle"));
        outputs.Add(await proxy.SayHello("London"));

        // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
        return outputs;
    }
}

Advanced usage

Use ILogger

public class HelloActivity : IHelloActivity
{
    public HelloActivity(ILoggerFactory loggerFactory)
    {
        // Create logger instance
        _logger = loggerFactory.CreateLogger<HelloActivity>();
    }
    
    private readonly ILogger _logger;

    [FunctionName(nameof(SayHello))]
    public Task<string> SayHello([ActivityTrigger] string name)
    {
        _logger.LogInformation($"Saying hello to {name}.");
        return Task.FromResult($"Hello {name}!");
    }
}

Retry options

public interface IHttpGetActivity
{
    // Declarative RetryOptions definition
    [RetryOptions("00:00:05", 10)]
    Task<string> HttpGet(string path);
}

public class HttpGetActivity : IHttpGetActivity
{
    public HttpGetActivity(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    private readonly HttpClient _httpClient;

    // In case of failure, retry is performed transparently
    [FunctionName(nameof(HttpGet))]
    public Task<string> HttpGet([ActivityTrigger] string path)
    {
        return _httpClient.GetStringAsync(path);
    }
}

Custom retry handler

public static class RetryStrategy
{
    // Implement custom retry handler
    public static bool HttpError(Exception ex)
    {
        return ex.InnerException is HttpRequestException;
    }
}

public interface IHttpGetActivity
{
    // Must be setting HandlerType and HandlerMethodName
    [RetryOptions("00:00:05", 10, HandlerType = typeof(RetryStrategy), HandlerMethodName = nameof(RetryStrategy.HttpError))]
    Task<string> HttpGet(string path);
}

public class HttpGetActivity : IHttpGetActivity
{
    public HttpGetActivity(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    private readonly HttpClient _httpClient;

    [FunctionName(nameof(HttpGet))]
    public Task<string> HttpGet([ActivityTrigger] string path)
    {
        return _httpClient.GetStringAsync(path);
    }
}

Blog

License

This project is licensed under the Apache License 2.0

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on DurableTask.TypedProxy:

Repository Stars
shibayan/keyvault-acmebot
Automated ACME SSL/TLS certificates issuer for Azure Key Vault (App Service / Container Apps / App Gateway / Front Door / CDN / others)
shibayan/appservice-acmebot
Automated ACME SSL/TLS certificates issuer for Azure App Service (Web Apps / Functions / Containers)
shibayan/containerapps-acmebot
Automated ACME SSL/TLS certificates issuer for Azure Container Apps (Custom domain / Custom DNS Suffix)
Version Downloads Last updated
2.2.2 4,688 12/15/2022
2.2.1 3,533 3/1/2021
2.2.0 1,060 12/5/2020
2.1.0 1,118 8/30/2020
2.0.0 1,670 11/3/2019