DEV Community

Cover image for PipeNet, Pipe lining in .Net
Ali Alp
Ali Alp

Posted on

PipeNet, Pipe lining in .Net

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"
    });


Enter fullscreen mode Exit fullscreen mode

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

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)