PowerPipe 1.1.1
See the version list below for details.
dotnet add package PowerPipe --version 1.1.1
NuGet\Install-Package PowerPipe -Version 1.1.1
<PackageReference Include="PowerPipe" Version="1.1.1" />
<PackageVersion Include="PowerPipe" Version="1.1.1" />
<PackageReference Include="PowerPipe" />
paket add PowerPipe --version 1.1.1
#r "nuget: PowerPipe, 1.1.1"
#:package PowerPipe@1.1.1
#addin nuget:?package=PowerPipe&version=1.1.1
#tool nuget:?package=PowerPipe&version=1.1.1
<p align="center"> <img src="https://github.com/mvSapphire/PowerPipe/blob/master/assets/readme-header.png?raw=true" alt="drawing" width="250"/> </p>
<span align="center">
</span>
A .NET Library for Constructing Advanced Workflows with Fluent Interface
PowerPipe is a versatile .NET library designed to streamline the process of building advanced workflows using a fluent interface. The primary objective of this project is to eliminate the need for writing boilerplate code when implementing workflows.
Check out Medium article 👀
If you like this project give it a star 🌟
🔥 Features and Benefits
- Lightweight
- Fluent interface
- Ease & Structured Workflow construction
- Dependency Injection support
- Developed using .NET 6
🧐 Sample use case
Imagine creating an e-commerce platform. The platform must process incoming customer orders, each demanding validation, inventory updates, and potentially more intricate steps.
public class ECommercePipelineService : IECommercePipelineService
{
private readonly IPipelineStepFactory _pipelineStepFactory;
private bool PaymentSucceed(ECommerceContext context) => context.PaymentResult.Status is PaymentStatus.Success;
public ECommercePipelineService(IPipelineStepFactory pipelineStepFactory)
{
_pipelineStepFactory = pipelineStepFactory;
}
public IPipeline<OrderResult> BuildPipeline()
{
var context = new ECommerceContext();
return new PipelineBuilder<ECommerceContext, OrderResult>(_pipelineStepFactory, context)
.Add<OrderValidationStep>()
.Add<PaymentProcessingStep>()
.OnError(PipelineStepErrorHandling.Retry, retryInterval: TimeSpan.FromSeconds(2), maxRetryCount: 2)
.If(PaymentSucceed, b => b
.Add<OrderConfirmationStep>()
.Add<InventoryReservationStep>())
.Parallel(b => b
.Add<CustomerNotificationsStep>()
.Add<AnalyticsAndReportingStep>(), maxDegreeOfParallelism: 2)
.Build();
}
}
🛠️ Getting started
Installation
- Package Manager Console
Install-Package PowerPipe
Install-Package PowerPipe.Extensions.MicrosoftDependencyInjection
- .NET CLI
dotnet add package PowerPipe
dotnet add package PowerPipe.Extensions.MicrosoftDependencyInjection
Building pipeline
- Create pipeline context and result
public class SampleContext : PipelineContext<SampleResult>
{
// Properties and methods specific to the context
}
public class SampleResult
{
// Implementation details
}
- Create pipeline steps
public class SampleStep1 : IPipelineStep<SampleContext>
{
// Implementation details…
}
public class SampleStep2 : IPipelineStep<OrderContext>
{
// Implementation details…
}
- Define your pipeline
- Use
Add<T>method to add a step to your pipeline
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.Add<SampleStep1>()
.Add<SampleStep2>()
.Build();
- Use
AddIf<T>method to add a step to the pipeline based on the predicate
// Define predicate based on context
private bool ExecuteStep2(OrderProcessingContext context) =>
context.ExecuteStep2Allowed;
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.Add<SampleStep1>()
.AddIf<SampleStep2>(ExecuteStep2)
.Build();
- Use
AddIfElse<TFirst, TSecond>method to add one of the steps by the predicate
private bool ExecuteStep2(OrderProcessingContext context) =>
context.ExecuteStep2Allowed;
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.AddIfElse<SampleStep1, SampleStep2>(ExecuteStep2)
.Build();
- Use
Ifmethod to add a nested pipeline based on a predicate
private bool ExecuteNestedPipeline(OrderProcessingContext context) =>
context.ExecuteNestedPipelineAllowed;
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.If(ExecuteNestedPipeline, b => b
.Add<SampleStep1>()
.Add<SampleStep2>())
.Build();
- Use
Parallelmethod to execute your steps in parallel
In order to execute steps in parallel your steps should implement
IPipelineParallelStep<TContext>interface
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.Parallel(b => b
.Add<SampleParallelStep1>()
.Add<SampleParallelStep2>(), maxDegreeOfParallelism: 3)
.Build();
- Use
OnErrormethod to add error-handling behavior
Currently available only two types of error handling
SuppressandRetry
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.Add<SampleStep1>()
.OnError(PipelineStepErrorHandling.Retry)
.Build();
- Use
CompensateWithmethod to add a compensation step to the previously added step in the pipeline
Compensation steps should implement
IPipelineCompensationStep<TContext>
public class SampleStep1Compensation : IPipelineCompensationStep<SampleContext> {}
var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
.Add<SampleStep1>()
.CompensateWith<SampleStep1Compensation>()
.Build();
- Extensions: Microsoft Dependency Injection
The
PowerPipe.Extensions.MicrosoftDependencyInjectionextension provides integration with Microsoft Dependency Injection.
- Use
AddPowerPipeto register step factory
public static IServiceCollection AddPowerPipe(this IServiceCollection serviceCollection)
- Use
AddPowerPipeStep,AddPowerPipeParallelStep,AddPowerPipeCompensationStepmethods to register your steps
services
.AddPowerPipeStep<SampleStep1, SampleContext>()
.AddPowerPipeParallelStep<SampleParallelStep1, SampleContext>()
.AddPowerPipeCompensationStep<SampleStep1Compensation, SampleContext>()
// other steps ...
;
Check out sample project 👀
| 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. 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. |
-
net6.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on PowerPipe:
| Package | Downloads |
|---|---|
|
PowerPipe.Extensions.MicrosoftDependencyInjection
A library for .NET that uses a fluent interface to construct advanced workflows with ease |
|
|
PowerPipe.Visualization
A library for .NET that uses a fluent interface to construct advanced workflows with ease |
GitHub repositories
This package is not used by any popular GitHub repositories.