Chain.NetCore
6.0.3
See the version list below for details.
dotnet add package Chain.NetCore --version 6.0.3
NuGet\Install-Package Chain.NetCore -Version 6.0.3
<PackageReference Include="Chain.NetCore" Version="6.0.3" />
paket add Chain.NetCore --version 6.0.3
#r "nuget: Chain.NetCore, 6.0.3"
// Install Chain.NetCore as a Cake Addin #addin nuget:?package=Chain.NetCore&version=6.0.3 // Install Chain.NetCore as a Cake Tool #tool nuget:?package=Chain.NetCore&version=6.0.3
chain
Chain is a pattern that I found useful in my places in my code. It is NOT the chain-of-responsibility and it is not the work-flow or pipeline. It is a combination of all.
Chain contains of a manager class that implements IChain<T>
plus as many link classes which they should implement ILink<T>
.
'IChain' have a methid called 'ExecuteAll()' which technically
goes thourgh the Execute()
method of all links and run them one by one. The manager class is responsible to define the sequence
of the links.
Manager class also can have a method called ClosingAction
. This action will be run after execution of all links.
Each links has two different abilities. They can stop execution of the chain, and they can stop propagation of the chain and jump to ClosingAction. The difference between two is that ClosingAction method, if exists, won't be run for StopExecution() but it will for StopPropagation().
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
.
var message = new Message { Name = "M1" };
var c = new EmptyChain<Message>();
c.AddLink<L1>();
c.AddLink<L2>();
c.ExecuteAll(message);
EmptyChain
can also be used in a different way:
public class L1L2Chain : EmptyChain<Message>
{
public L1L2Chain()
{
AddLink<L1>();
AddLink<L2>();
}
}
var c = new L1L2Chain();
c.ExecuteAll(message);
Chains can also be created in IoC registration. This gives the flexibility to define the sequence of the chain in the IoC.
_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;
}
Product | Versions 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. |
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.