Chain.NetCore
8.0.0
dotnet add package Chain.NetCore --version 8.0.0
NuGet\Install-Package Chain.NetCore -Version 8.0.0
<PackageReference Include="Chain.NetCore" Version="8.0.0" />
<PackageVersion Include="Chain.NetCore" Version="8.0.0" />
<PackageReference Include="Chain.NetCore" />
paket add Chain.NetCore --version 8.0.0
#r "nuget: Chain.NetCore, 8.0.0"
#:package Chain.NetCore@8.0.0
#addin nuget:?package=Chain.NetCore&version=8.0.0
#tool nuget:?package=Chain.NetCore&version=8.0.0
Chain Pattern for .NET
Chain is a powerful execution pattern designed for composing sequential operations in .NET. It combines aspects of the Chain of Responsibility pattern with workflow and pipeline concepts to provide flexible, ordered execution of operations.
Overview
Chain provides a clean architecture for building processing pipelines. A IChain<T> manager class orchestrates the execution of multiple ILink<T> implementations in sequence. The ExecuteAll() method iterates through each link's Execute() method, allowing the manager class to define the execution sequence.
Key Features
- Sequential Execution: Links execute in a defined order
- Flexible Control Flow: Links can stop execution or jump to the closing action
- Closing Action Support: Optional post-processing method that runs after all links
- Ready-to-Use Implementation: The
EmptyChain<T>class provides out-of-the-box functionality - Dependency Injection Support: Integrate seamlessly with .NET Core IoC containers
- Updated for .NET 8: Fully compatible with the latest .NET framework
Execution Control
Manager class also can have a method called ClosingAction. This action will be run after execution of all links.
Links have two control mechanisms:
- StopExecution(): Halts the chain without running ClosingAction
- StopPropagation(): Halts the chain but still executes ClosingAction (if defined)
Usage Examples
There is a ready to use chain called EmptyChain in this assembly. New chains can be implemented either directly from IChain or by
inheriting from EmptyChain.
Basic Usage with EmptyChain
Create a simple chain by composing links together:
var message = new Message { Name = "M1" };
var c = new EmptyChain<Message>();
c.AddLink<L1>();
c.AddLink<L2>();
c.ExecuteAll(message);
Custom Chain Class
Inherit from EmptyChain for custom chain definitions:
public class L1L2Chain : EmptyChain<Message>
{
public L1L2Chain()
{
AddLink<L1>();
AddLink<L2>();
}
}
var c = new L1L2Chain();
c.ExecuteAll(message);
Dependency Injection Integration
Define chains in your IoC container for maximum flexibility:
_container = new Container(_ => _.For<IChain<Message>>().Use(CreateChain()).Singleton());
private static IChain<Message> CreateChain()
{
var chain = new EmptyChain<Message>();
chain.AddLink<L1>();
chain.AddLink<L2>();
return chain;
}
License
MIT License - See LICENSE.md for details
Support
For issues, questions, or contributions, please visit the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.