A library designed to make use of the pipeline pattern.
You may extend the generic pipeline and override the process method defined
public class ProcessOrdersPipeline : Pipeline<OrdersCollection>
{
public ProcessOrdersPipeline()
{
}
// you must override the Process method
}
You must implement
IStage<T>
// stage one
public class CreateOrder : IStage<int>
{
public int Execute(int input)
{
// some logic to create an order
return 0;
}
}
// stage two
public class ProcessPayment : IStage<int>
{
public int Execute(int input)
{
// some logic to process a payment
return 0;
}
}
// stage three
public class SendInvoice : IStage<int>
{
public int Execute(int input)
{
// some logic to send an invoice
return 0;
}
}
C#
Pipeline<int> pipeline = new ProcessOrdersPipeline();
// alternatively you may use the Register method to add your stages
pipeline.Pipe(new CreateOrder())
.Pipe(new ProcessPayment())
.Pipe(new SendInvoice());
pipeline.Process(0);
VB.Net
Dim pipeline As Pipeline(Of Integer) = New ProcessOrdersPipeline()
// alternatively you may use the Register method to add your stages
pipeline.Pipe(New CreateOrder())
.Pipe(New ProcessPayment())
.Pipe(New SendInvoice())
pipeline.Process(0)
If you want to return a different type within a stage:
// A stage
public class SendInvoice : IMixedStage<bool,int>
{
public bool Execute(int input)
{
// some logic to send an invoice
return false;
}
}
Note: If you wish to use a mixed stage, you must inherit from MixedPipeline.
The pipeline runner conveniently implements the Process method
Pipeline<int> pipeline = new PipelineRunner<int>();
// using the Register method
pipeline.Register(new CreateOrder())
.Register(new ProcessPayment())
.Register(new SendInvoice());
// the result is determined by the last stage
pipeline.Process(0);
The aggregate pipeline runner works the same as the pipeline runner except that it uses the result from a previous stage as input into the next stage. A mixed stage is not supported here.
Pipeline<int> pipeline = new AggregatePipelineRunner<int>();
// using the Register method
pipeline.Register(new CreateOrder())
.Register(new ProcessPayment())
.Register(new SendInvoice());
// the result is determined by the last stage
pipeline.Process(0);
The task pipeline runner implements a mixed pipeline where the input can be a different type than output. Again, this pipeline runner implements the process method.
TaskPipelineRunner<int> p = new TaskPipelineRunner<int>(3);
p.Pipe(new CreateOrderTask())
.Pipe(new ProcessPaymentTask())
.Pipe(new SendInvoiceTask());
p.Process(0);
- Support asynchronous processing
- Allow for more arguments
- Tests,Tests,Tests