Simplifying a complex logic with the Chain of responsibility and builder patterns
Install it from Nuget
Check out the Repository
Usage
OrderData result= await new Pipe<OrderData>()
.Next(new OrderNode())
.Next(new ProducingNode())
.Finally(new CheckoutNode())
.Execute(new OrderData()
{
Name = "Coffee"
});
Node 1 in the pipe
public class OrderNode : Node<OrderData>
{
public override async Task<OrderData> Execute(OrderData param)
{
// Node 1's logic
return await base.Execute(param);
}
}
Node 2 in the pipe
public class ProducingNode : Node<OrderData>
{
public override async Task<OrderData> Execute(OrderData param)
{
// Node 2's logic
return await base.Execute(param);
}
}
Node 3 in the pipe
public class CheckoutNode : Node<OrderData>
{
public override async Task<OrderData> Execute(OrderData param)
{
// Node 3's logic
return await base.Execute(param);
}
}
Benchmark Summary
Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
---|---|---|---|---|---|---|---|
WithPipeNet | 221.3 ns | 4.37 ns | 10.87 ns | 0.0713 | - | - | 448 B |
RunWithoutPipeNet | 218.0 ns | 4.41 ns | 10.90 ns | 0.0892 | - | - | 560 B |
Install it from Nuget
Check out the Repository
Happy coding :)
Top comments (0)