AppStream.DurablePatterns 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package AppStream.DurablePatterns --version 1.0.2                
NuGet\Install-Package AppStream.DurablePatterns -Version 1.0.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="AppStream.DurablePatterns" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AppStream.DurablePatterns --version 1.0.2                
#r "nuget: AppStream.DurablePatterns, 1.0.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 AppStream.DurablePatterns as a Cake Addin
#addin nuget:?package=AppStream.DurablePatterns&version=1.0.2

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

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

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

Function Startup
using AppStream.DurablePatterns;

[assembly: FunctionsStartup(typeof(Startup))]

internal class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        builder.Services
            .AddDurablePatterns(cfg => cfg.AddActivitiesFromAssembly(typeof(GetItems).Assembly));
    }
}
IPatternActivity classes
using AppStream.DurablePatterns;

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

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

    public Task<List<Item>> RunAsync(object? input)
    {
        return _repository.GetItemsAsync();
    }
}

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

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

    public Task<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(processedItems);
    }
}

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

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

    public Task<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(processedItems);
    }
}
Orchestrator function
using AppStream.DurablePatterns;

internal class MyOrchestrator
{
    private readonly IDurablePatterns _patterns;

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

    [FunctionName("Orchestrator")]
    public Task<ExecutionResult> RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext 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.2 166 6/6/2024
3.1.1 194 8/16/2023
3.1.0 166 8/14/2023
3.0.2 193 7/19/2023
3.0.1 168 7/19/2023
3.0.0 177 7/17/2023
2.0.0 188 7/6/2023
1.0.2 175 6/7/2023
1.0.1 167 5/15/2023
1.0.1-CI-20230512-154711 132 5/12/2023
1.0.0 169 5/6/2023