{"id":19100537,"url":"https://github.com/mvSapphire/PowerPipe","last_synced_at":"2025-04-18T17:33:59.630Z","repository":{"id":38344616,"uuid":"459250010","full_name":"mvSapphire/PowerPipe","owner":"mvSapphire","description":"A library for .NET that uses a fluent interface to construct advanced workflows with ease.","archived":false,"fork":false,"pushed_at":"2024-07-31T14:45:06.000Z","size":494,"stargazers_count":177,"open_issues_count":5,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-01T07:46:19.440Z","etag":null,"topics":["builder","c-sharp","chain","chain-of-responsibility","dotnet-core","pipe","pipeline","powerpipe","workflow","workflow-engine"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvSapphire.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-14T17:01:29.000Z","updated_at":"2024-08-01T07:46:19.441Z","dependencies_parsed_at":"2024-02-08T15:57:09.834Z","dependency_job_id":"191fda8b-8b45-43e3-81b8-14204e7931c6","html_url":"https://github.com/mvSapphire/PowerPipe","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvSapphire%2FPowerPipe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvSapphire%2FPowerPipe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvSapphire%2FPowerPipe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvSapphire%2FPowerPipe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvSapphire","download_url":"https://codeload.github.com/mvSapphire/PowerPipe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783096,"owners_count":17201904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["builder","c-sharp","chain","chain-of-responsibility","dotnet-core","pipe","pipeline","powerpipe","workflow","workflow-engine"],"created_at":"2024-11-09T03:52:52.954Z","updated_at":"2025-04-18T17:33:59.623Z","avatar_url":"https://github.com/mvSapphire.png","language":"C#","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/mvSapphire/PowerPipe/blob/master/assets/readme-header.png?raw=true\" alt=\"drawing\" width=\"250\"/\u003e\n\u003c/p\u003e\n\n\u003cspan align=\"center\"\u003e\n\n[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/mvSapphire/PowerPipe/build.yml)](https://github.com/mvSapphire/PowerPipe/actions)\n![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/mvSapphire/87b833b49852f7f088e1d4d913600a91/raw/code-coverage.json)\n[![Nuget](https://img.shields.io/nuget/v/PowerPipe)](https://www.nuget.org/packages/PowerPipe)\n[![Nuget](https://img.shields.io/nuget/dt/PowerPipe)](https://www.nuget.org/stats/packages/PowerPipe?groupby=Version)\n\n\u003c/span\u003e\n\n# A .NET Library for Constructing Advanced Workflows with Fluent Interface\n\nPowerPipe 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.\n\nCheck out [Medium article](https://medium.com/@m.vorchakov97/from-chaos-to-clarity-enhance-data-processing-with-powerpipe-in-net-262ac34a4923) 👀\n\nIf you like this project give it a star 🌟\n\n## 🔥 Features and Benefits\n\n- Lightweight\n- Fluent interface\n- Conditional steps\n- Parallel steps execution\n- Nested pipelines\n- Error handling\n- Steps compensation\n- Ease \u0026 Structured Workflow construction\n- Dependency Injection support\n- Developed using latest .NET\n\n## 🧐 Sample use case\n\nImagine creating an e-commerce platform. The platform must process incoming customer orders, each demanding validation, inventory updates, and potentially more intricate steps.\n\n```csharp\npublic  class  ECommercePipelineService : IECommercePipelineService\n{\n    private  readonly  IPipelineStepFactory _pipelineStepFactory;\n\n    private bool PaymentSucceed(ECommerceContext context) =\u003e context.PaymentResult.Status is PaymentStatus.Success;\n\n    public  ECommercePipelineService(IPipelineStepFactory pipelineStepFactory)\n    {\n        _pipelineStepFactory  =  pipelineStepFactory;\n    }\n\n    public IPipeline\u003cOrderResult\u003e BuildPipeline()\n    {\n        var context = new ECommerceContext();\n\n        return new PipelineBuilder\u003cECommerceContext, OrderResult\u003e(_pipelineStepFactory, context)\n            .Add\u003cOrderValidationStep\u003e()\n            .Add\u003cPaymentProcessingStep\u003e()\n                .OnError(PipelineStepErrorHandling.Retry,  retryInterval:  TimeSpan.FromSeconds(2), maxRetryCount: 2)\n            .If(PaymentSucceed, b =\u003e b\n                .Add\u003cOrderConfirmationStep\u003e()\n                .Add\u003cInventoryReservationStep\u003e())\n            .Parallel(b =\u003e b\n                .Add\u003cCustomerNotificationsStep\u003e()\n                .Add\u003cAnalyticsAndReportingStep\u003e(), maxDegreeOfParallelism: 2)\n            .Build();\n    }\n}\n```\n\n## 🤩 Workflow visualization\n\nSometimes workflows could be too big to track what is happening.\n\nThat's why we created a workflow visualization tool. This tool was designed with simplicity in mind.\nYou have to add just **few lines of code** to make this work!\n\n### Install required packages\n\n- Package Manager Console\n```\nInstall-Package PowerPipe.Visualization\nInstall-Package PowerPipe.Visualization.Extensions.MicrosoftDependencyInjection\n```\n\n- .NET CLI\n```\ndotnet add package PowerPipe.Visualization\ndotnet add package PowerPipe.Visualization.Extensions.MicrosoftDependencyInjection\n```\n\n### Usage\n\nIn your Startup/Program file add required services and register middleware:\n\n``` csharp\nbuilder.Services.AddPowerPipeVisualization(o =\u003e o.ScanFromType(typeof(ECommercePipelineService)));\n\n// ...\n\napp.UsePowerPipeVisualization();\n```\n\nThen start you application and navigate to `/powerpipe` endpoint.\n\nAnd workflow from the sample above parsed to this beautiful diagram. 🌟\n\n\u003cimg src=\"https://github.com/mvSapphire/PowerPipe/blob/master/assets/readme-diagram-sample.png?raw=true\" alt=\"drawing\" width=\"800\"/\u003e\n\n\u003e Note! This is the very first version of workflow visualization! Looking forward to your feedback 🤗\n\n\u003e Known issues: \n\u003e - OnError parsing could lead to missing steps on the diagram\n\u003e - Double links between entities\n\n## 🛠️ Getting started\n\n### Installation\n\n- Package Manager Console\n```\nInstall-Package PowerPipe\nInstall-Package PowerPipe.Extensions.MicrosoftDependencyInjection\n```\n\n- .NET CLI\n```\ndotnet add package PowerPipe\ndotnet add package PowerPipe.Extensions.MicrosoftDependencyInjection\n```\n\n###  Building pipeline\n\n1. **Create pipeline context and result**\n\n```csharp\npublic class SampleContext : PipelineContext\u003cSampleResult\u003e  \n{  \n    // Properties and methods specific to the context  \n}\n\npublic class SampleResult\n{\n    // Implementation details\n}\n```\n\n2. **Create pipeline steps**\n\n```csharp\npublic class SampleStep1 : IPipelineStep\u003cSampleContext\u003e  \n{  \n    // Implementation details…\n}\n  \npublic  class  SampleStep2 : IPipelineStep\u003cOrderContext\u003e  \n{  \n    // Implementation details…\n}\n```\n\n3. **Define your pipeline**\n\n- Use `Add\u003cT\u003e` method to add a step to your pipeline\n\n```csharp\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .Add\u003cSampleStep1\u003e()\n    .Add\u003cSampleStep2\u003e()\n    .Build();\n```\n\n- Use `AddIf\u003cT\u003e` method to add a step to the pipeline based on the predicate \n\n```csharp\n// Define predicate based on context\nprivate bool ExecuteStep2(OrderProcessingContext context) =\u003e\n    context.ExecuteStep2Allowed;\n\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .Add\u003cSampleStep1\u003e()\n    .AddIf\u003cSampleStep2\u003e(ExecuteStep2) \n    .Build();\n```\n\n- Use `AddIfElse\u003cTFirst, TSecond\u003e` method to add one of the steps by the predicate\n\n```csharp\nprivate bool ExecuteStep2(OrderProcessingContext context) =\u003e\n    context.ExecuteStep2Allowed;\n\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .AddIfElse\u003cSampleStep1, SampleStep2\u003e(ExecuteStep2) \n    .Build();\n```\n\n- Use `If` method to add a nested pipeline based on a predicate\n\n```csharp\nprivate bool ExecuteNestedPipeline(OrderProcessingContext context) =\u003e\n    context.ExecuteNestedPipelineAllowed;\n\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .If(ExecuteNestedPipeline, b =\u003e b\n        .Add\u003cSampleStep1\u003e()\n        .Add\u003cSampleStep2\u003e())\n    .Build();\n```\n\n- Use `Parallel` method to execute your steps in parallel\n\n\u003e In order to execute steps in parallel your steps should implement `IPipelineParallelStep\u003cTContext\u003e` interface\n\n```csharp\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .Parallel(b =\u003e b  \n        .Add\u003cSampleParallelStep1\u003e()\n        .Add\u003cSampleParallelStep2\u003e(), maxDegreeOfParallelism: 3)\n    .Build();\n```\n\n- Use `OnError` method to add error-handling behavior\n\n\u003e Currently available only two types of error handling `Suppress` and `Retry`\n\n```csharp\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .Add\u003cSampleStep1\u003e()\n        .OnError(PipelineStepErrorHandling.Retry)\n    .Build();\n```\n\n- Use `CompensateWith` method to add a compensation step to the previously added step in the pipeline\n\n\u003e Compensation steps should implement `IPipelineCompensationStep\u003cTContext\u003e`\n\n```csharp\npublic class SampleStep1Compensation : IPipelineCompensationStep\u003cSampleContext\u003e {}\n\nvar pipeline = new PipelineBuilder\u003cOrderProcessingContext, Order\u003e()\n    .Add\u003cSampleStep1\u003e()\n        .CompensateWith\u003cSampleStep1Compensation\u003e()\n    .Build();\n```\n\n4. **Extensions: Microsoft Dependency Injection**\n\nThe `PowerPipe.Extensions.MicrosoftDependencyInjection` extension provides integration with Microsoft Dependency Injection.\n\n- Use `AddPowerPipe` to register all required services and scan libraries for your step implementations.\n\n```csharp\npublic static IServiceCollection AddPowerPipe(\n    this IServiceCollection serviceCollection,\n    PowerPipeConfiguration configuration)\n```\n\nBy default all found implementations will be registered as Transient.\n\n```csharp\nservices.AddPowerPipe(cfg =\u003e\n{\n    cfg.RegisterServicesFromAssemblies(Assembly.GetExecutingAssembly());\n});\n```\n\nBut you can configure service lifetime per step implementation.\n\n```csharp\nservices.AddPowerPipe(cfg =\u003e\n{\n    cfg.RegisterServicesFromAssemblies(typeof(Program).Assembly)\n        .ChangeStepsDefaultLifetime(ServiceLifetime.Scoped)\n        .AddSingleton\u003cStep1\u003e()\n        .AddTransient\u003cStep2\u003e()\n        .AddTransient(typeof(Step2));\n});\n```\n\n\nCheck out [sample project](samples/PowerPipe.Sample) 👀\n","funding_links":[],"categories":["others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FmvSapphire%2FPowerPipe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FmvSapphire%2FPowerPipe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FmvSapphire%2FPowerPipe/lists"}