EasyChain 1.0.5-g5a6d0b3b32

This is a prerelease version of EasyChain.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package EasyChain --version 1.0.5-g5a6d0b3b32
                    
NuGet\Install-Package EasyChain -Version 1.0.5-g5a6d0b3b32
                    
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="EasyChain" Version="1.0.5-g5a6d0b3b32" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyChain" Version="1.0.5-g5a6d0b3b32" />
                    
Directory.Packages.props
<PackageReference Include="EasyChain" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EasyChain --version 1.0.5-g5a6d0b3b32
                    
#r "nuget: EasyChain, 1.0.5-g5a6d0b3b32"
                    
#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.
#:package EasyChain@1.0.5-g5a6d0b3b32
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EasyChain&version=1.0.5-g5a6d0b3b32&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=EasyChain&version=1.0.5-g5a6d0b3b32&prerelease
                    
Install as a Cake Tool

EasyChain

EasyChain is a lightweight .NET library designed for implementing the Chain of Responsibility pattern. It enables you to define a sequence of handlers to process messages in a flexible and decoupled manner.

<p align="left"> <a href="https://github.com/cleberMargarida/easy-chain/actions/workflows/workflow.yml"> <img src="https://github.com/cleberMargarida/easy-chain/actions/workflows/workflow.yml/badge.svg" alt="Build-deploy pipeline"> </a> <a href="https://www.nuget.org/packages/EasyChain"> <img src="https://img.shields.io/nuget/vpre/EasyChain.svg" alt="EasyChain Nuget Version"> </a>
<a href="https://github.com/cleberMargarida/easy-chain/actions/runs/10553862586#summary-29234823720"> <img src="https://camo.githubusercontent.com/ff5d6927f201cb1122f1a454a524c334a4406398af1ce88c5ac4c5fd57501ae9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6465253230436f7665726167652d3130302532352d737563636573733f7374796c653d666c6174" alt="EasyChain Coverage"> </a> </p>

Chain of responsibility

A light-weight and straightforward library for implementing the chain of responsibility pattern. Consider take a look at Source Making - Chain of Responsibility

flowchart LR
    A[Chain Run] -->|message| C{Decision 1}
    C -->|Yes| D[await next]
    C -->|No| P[Return]
    D --> F{Decision 2}
    F -->|Yes| H[await next]
    F -->|No| Q[Return]
    H --> I{Decision 3}
    I -->|Yes| J[await next]
    I -->|No| R[Return]

Features

  • .NET Standard Support: Compatible with all .NET applications, including .NET Core, .NET 5, .NET 6, .NET 7, .NET 8, and .NET 9.
  • Integration with Dependency Injection: Fully supports Microsoft.Extensions.DependencyInjection, including various lifetime options.
  • Fluent API: Define and configure chains of handlers using a simple and expressive fluent API.
  • Asynchronous Processing: Handles messages asynchronously.
  • Runtime Compilation: We make usage System.Linq.Expressions to compile methods dynamically at runtime, ensuring no code is embedded between your handlers.
  • Ease of Use: Extremely straightforward to set up and use.

Installation

To install EasyChain, add the following package to your project via NuGet:

dotnet add package EasyChain

Usage

Here's a quick example to get you started:

  1. Define Your Chain
class CarChain : IChainBuilder<Car>
{
    public void Configure(IChainConfig<Car> callChain)
    {
        callChain.Add<CarYearHandler>();
        callChain.Add<CarModelHandler>();
    }
}

class CarYearHandler : IHandler<Car>
{
    public async Task Handle(Car message, ChainHandling<Car> next)
    {
        if (message.Year > 1960)
            await next(message);
    }
}

class CarModelHandler : IHandler<Car>
{
    public async Task Handle(Car message, ChainHandling<Car> next)
    {
        if (message.Model == "FooModel")
            await next(message);
    }
}
  1. Register the Chain
builder.Services.AddChain<CarChain>();
  1. Run the Chain
IChain<Car> chain = app.Services.GetService<IChain<Car>>();

var message = new Car
{
    Model = "FooModel",
    Year = 2024,
};

await chain.Run(message);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any questions or support, please reach out to cleber.margarida@outlook.com.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.10-gd800b6c417 91 9/19/2024
1.0.9-g84549e6040 88 9/18/2024
1.0.8-ga458241a04 79 9/18/2024
1.0.6-g02eb2d1167 76 9/18/2024
1.0.5-g5a6d0b3b32 80 8/26/2024
1.0.4-g5d078facc3 94 8/26/2024
0.0.0-gefbb5722af 80 8/26/2024
0.0.0-gc451631ecf 77 8/26/2024
0.0.0-g9078683bbb 80 8/26/2024
0.0.0-g88c59b3e2e 71 8/26/2024
0.0.0-g854dbc783b 75 8/26/2024
0.0.0-g76f2ca2a54 75 8/26/2024
0.0.0-g768ab18893 78 8/26/2024
0.0.0-g70e38b4ba6 78 8/26/2024
0.0.0-g6d3bd44630 80 8/26/2024
0.0.0-g3a1c312e1b 73 8/26/2024
0.0.0-g35dd161270 80 8/26/2024
0.0.0-g027d335fae 75 8/26/2024