PowerPipe.Extensions.MicrosoftDependencyInjection 1.2.0-rc4

This is a prerelease version of PowerPipe.Extensions.MicrosoftDependencyInjection.
There is a newer version of this package available.
See the version list below for details.
dotnet add package PowerPipe.Extensions.MicrosoftDependencyInjection --version 1.2.0-rc4                
NuGet\Install-Package PowerPipe.Extensions.MicrosoftDependencyInjection -Version 1.2.0-rc4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PowerPipe.Extensions.MicrosoftDependencyInjection" Version="1.2.0-rc4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PowerPipe.Extensions.MicrosoftDependencyInjection --version 1.2.0-rc4                
#r "nuget: PowerPipe.Extensions.MicrosoftDependencyInjection, 1.2.0-rc4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PowerPipe.Extensions.MicrosoftDependencyInjection as a Cake Addin
#addin nuget:?package=PowerPipe.Extensions.MicrosoftDependencyInjection&version=1.2.0-rc4&prerelease

// Install PowerPipe.Extensions.MicrosoftDependencyInjection as a Cake Tool
#tool nuget:?package=PowerPipe.Extensions.MicrosoftDependencyInjection&version=1.2.0-rc4&prerelease                

<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">

GitHub Workflow Status (with event) badge Nuget Nuget

</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

  1. Create pipeline context and result
public class SampleContext : PipelineContext<SampleResult>  
{  
    // Properties and methods specific to the context  
}

public class SampleResult
{
    // Implementation details
}
  1. Create pipeline steps
public class SampleStep1 : IPipelineStep<SampleContext>  
{  
    // Implementation details…
}
  
public  class  SampleStep2 : IPipelineStep<OrderContext>  
{  
    // Implementation details…
}
  1. 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 If method 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 Parallel method 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 OnError method to add error-handling behavior

Currently available only two types of error handling Suppress and Retry

var pipeline = new PipelineBuilder<OrderProcessingContext, Order>()
    .Add<SampleStep1>()
        .OnError(PipelineStepErrorHandling.Retry)
    .Build();
  • Use CompensateWith method 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();
  1. Extensions: Microsoft Dependency Injection

The PowerPipe.Extensions.MicrosoftDependencyInjection extension provides integration with Microsoft Dependency Injection.

  • Use AddPowerPipe to register all required services and scan libraries for your step implementations.
public static IServiceCollection AddPowerPipe(
    this IServiceCollection serviceCollection,
    PowerPipeConfiguration configuration)

By default all found implementations will be registered as Transient.

services.AddPowerPipe(cfg =>
{
    cfg.RegisterServicesFromAssemblies(Assembly.GetExecutingAssembly());
});

But you can configure service lifetime per step implementation.

services.AddPowerPipe(cfg =>
{
    cfg.RegisterServicesFromAssemblies(typeof(Program).Assembly)
        .ChangeDefaultLifetime(ServiceLifetime.Scoped) // to override default lifetime
        .AddSingleton<Step1>()
        .AddTransient<Step2>()
        .AddTransient(typeof(Step2));
});

Check out sample project 👀

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 5,895 7/31/2024
3.0.0-rc1 56 7/31/2024
2.0.0 1,532 3/22/2024
2.0.0-rc2 307 2/9/2024
2.0.0-rc1 115 2/8/2024
1.2.0 17,638 11/13/2023
1.2.0-rc5 106 11/10/2023
1.2.0-rc4 124 11/9/2023
1.2.0-rc3 100 11/7/2023
1.2.0-rc2 94 11/7/2023
1.2.0-rc 92 11/7/2023
1.1.2 343 9/21/2023
1.1.2-beta 232 9/21/2023
1.1.1 144 9/12/2023
1.1.0 142 9/11/2023
1.1.0-rc 136 9/6/2023
1.0.3 5,308 7/17/2023
1.0.2 11,331 2/8/2023
1.0.1 572 1/16/2023
1.0.0 308 1/3/2023
1.0.0-beta 140 1/3/2023
0.1.10 4,857 5/10/2022
0.1.9 414 5/10/2022
0.1.8 426 5/6/2022
0.1.7 409 5/5/2022
0.1.6 407 4/21/2022
0.1.5 420 4/21/2022
0.1.4 405 4/21/2022
0.1.3 413 4/18/2022
0.1.2 425 2/14/2022
0.1.1 409 2/14/2022
0.1.0 461 2/14/2022