EasyChain 1.0.9-g84549e6040
See the version list below for details.
dotnet add package EasyChain --version 1.0.9-g84549e6040
NuGet\Install-Package EasyChain -Version 1.0.9-g84549e6040
<PackageReference Include="EasyChain" Version="1.0.9-g84549e6040" />
<PackageVersion Include="EasyChain" Version="1.0.9-g84549e6040" />
<PackageReference Include="EasyChain" />
paket add EasyChain --version 1.0.9-g84549e6040
#r "nuget: EasyChain, 1.0.9-g84549e6040"
#:package EasyChain@1.0.9-g84549e6040
#addin nuget:?package=EasyChain&version=1.0.9-g84549e6040&prerelease
#tool nuget:?package=EasyChain&version=1.0.9-g84549e6040&prerelease
Here's the updated README
with the additional example for building in-line:
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/64e5de57df4409175a42e38d3fe23291f6fe8bc1ccf2bf2a2007c7af2df7832c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6465253230436f7665726167652d38342532352d737563636573733f7374796c653d666c6174" alt="EasyChain Coverage">
</a>
</p>
Chain of Responsibility
A lightweight and straightforward library for implementing the chain of responsibility pattern. 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: Uses
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 : IChainConfig<Car>
{
public void Configure(IChainBuilder<Car> callChain)
{
callChain.SetNext<CarYearHandler>()
.SetNext<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);
}
}
2. Register the Chain
builder.Services.AddChain<CarChain>();
3. Run the Chain
IChain<Car> chain = app.Services.GetService<IChain<Car>>();
var message = new Car
{
Model = "FooModel",
Year = 2024,
};
await chain.Run(message);
4. Forking Example
EasyChain allows you to fork the chain into multiple branches and merge them back later:
class CarChain : IChainConfig<Car>
{
public void Configure(IChainBuilder<Car> callChain)
{
callChain.SetNext<CarYearHandler>()
.Fork((left, right) =>
{
left.SetNext<EngineSizeHandler>();
right.SetNext<CarModelHandler>();
})
.Merge()
.SetNext<CarPriceHandler>();
}
}
In this example:
- The chain forks after
CarYearHandler
into two branches: one continues withEngineSizeHandler
, and the other withCarModelHandler
. - After the fork, the branches are merged, and the chain continues with
CarPriceHandler
.
5. Building In-Line
You can also build your chain in-line using the CreateBuilder
method:
var chain = Chain<object>.CreateBuilder()
.SetNext<TestHandler>()
.SetNext<TestHandler2>()
.Build();
In this example, the chain is configured and built in a single statement, allowing for concise and clear setup.
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 | Versions 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. |
-
.NETStandard 2.1
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 |