AppStream.DurablePatterns 3.1.1

dotnet add package AppStream.DurablePatterns --version 3.1.1
NuGet\Install-Package AppStream.DurablePatterns -Version 3.1.1
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="AppStream.DurablePatterns" Version="3.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AppStream.DurablePatterns --version 3.1.1
#r "nuget: AppStream.DurablePatterns, 3.1.1"
#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 AppStream.DurablePatterns as a Cake Addin
#addin nuget:?package=AppStream.DurablePatterns&version=3.1.1

// Install AppStream.DurablePatterns as a Cake Tool
#tool nuget:?package=AppStream.DurablePatterns&version=3.1.1

AppStream Studio

License NuGet Package Build Status

Durable Patterns

Welcome to the Durable Patterns Library!

Our library is here to help you make better use of Azure Durable Functions Framework without unnecessary boilerplate code. It provides fluent interface for orchestrator function to easily build efficient and scalable processes that implements the typical application patterns like:

  • fan out / fan in
  • function chaining
  • Monitoring pattern

You just inject business logic enclosed in IPatternActivity implementations and our library will take care of creating activity functions, passing the arguments and injecting objects without the need to write repeatable sections.

Get Started with Durable Patterns

Durable Patterns can be installed using the Nuget package manager or the dotnet CLI.

dotnet add package AppStream.DurablePatterns

To use this library you need to instruct durable functions framework to look for activity functions not only in your startup project by adding this property in <PropertyGroup> of your startup project's csproj:

<FunctionsInDependencies>true</FunctionsInDependencies>

Example - fan out / fan in

Program.cs
using AppStream.DurablePatterns;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(services => services.AddDurablePatterns(cfg => cfg.AddActivitiesFromAssembly(typeof(GetItems).Assembly))
    .Build();

host.Run();
IPatternActivity classes
using AppStream.DurablePatterns;

internal class GetItems : IPatternActivity<List<Item>>
{
    private readonly IRepository _repository;

    public GetItems(IRepository repository)
    {
        _repository = repository;
    }

    public async Task<PatternActivityResult<List<Item>>> RunAsync(object? input)
    {
        return new PatternActivityResult<List<Item>>(
            value: await _repository.GetItemsAsync(),
            output: new { whateverYouWantToBeDisplayedInOrchestratorOutput = true });
    }
}

internal class FanOut : IPatternActivity<List<Item>, List<Item>>
{
    private readonly IItemProcessingService _service;

    public FanOut(IItemProcessingService service)
    {
        _service = service;
    }

    public Task<PatternActivityResult<List<Item>>> RunAsync(List<Item> input)
    {
        // this block of code will be executed in parallel batches
        var processedItems = new List<Item>();

        foreach (var item in input)
        {
            processedItems.Add(_service.Process(item));
        }

        return Task.FromResult(new PatternActivityResult<List<Item>>(processedItems, new { foo = "bar" }));
    }
}

internal class FanIn : IPatternActivity<List<Item>, List<Item>>
{
    private readonly IOtherItemProcessingService _service;

    public FanIn(IOtherItemProcessingService service)
    {
        _service = service;
    }

    public Task<PatternActivityResult<List<Item>>> RunAsync(List<Item> input)
    {
        // this block of code will be executed once and the input will be all items returned from all FanOut activities
        var processedItems = new List<Item>();

        foreach (var item in input)
        {
            processedItems.Add(_service.Process(item));
        }

        return Task.FromResult(new PatternActivityResult<List<Item>>(processedItems, new { foo = "bar" }));
    }
}
Orchestrator function
using AppStream.DurablePatterns;

internal class MyOrchestrator
{
    private readonly IDurablePatterns _patterns;

    public MyOrchestrator(
        IDurablePatterns patterns)
    {
        _patterns = patterns;
    }

    [Function("Orchestrator")]
    public Task<ExecutionResult> RunOrchestrator(
        [OrchestrationTrigger] TaskOrchestrationContext context)
    {
        return _patterns
            .WithContext(context)
            .RunActivity<GetItems>()
            .FanOutFanIn<FanOut>(new FanOutFanInOptions(BatchSize: 2, ParallelActivityFunctionsCap: 2))
            .RunActivity<FanIn>()
            .ExecuteAsync();
    }
}

Roadmap

  • Updating orchestration status during execution
  • Support for lambdas instead of explicit IPatternActivity implementations
  • Naming the activities for easier debugging
  • Add support for Monitoring pattern
  • Add support for Human interaction pattern

Contributing

Contributions to this open source library are highly appreciated! If you're interested in helping out, please feel free to submit a pull request with your changes. We welcome contributions of all kinds, whether it's bug fixes, new features, or just improving the documentation. Please ensure that your code is well-documented, tested, and adheres to the coding conventions used in the project. Don't hesitate to reach out if you have any questions or need help getting started. You can open an issue on GitHub or email us at contact@appstream.studio - we're happy to assist you in any way we can.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.1 162 8/16/2023
3.1.0 140 8/14/2023
3.0.2 159 7/19/2023
3.0.1 143 7/19/2023
3.0.0 153 7/17/2023
2.0.0 157 7/6/2023
1.0.2 147 6/7/2023
1.0.1 140 5/15/2023
1.0.1-CI-20230512-154711 103 5/12/2023
1.0.0 142 5/6/2023