Pipelines 1.0.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Pipelines --version 1.0.0
                    
NuGet\Install-Package Pipelines -Version 1.0.0
                    
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="Pipelines" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pipelines" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Pipelines" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pipelines --version 1.0.0
                    
#r "nuget: Pipelines, 1.0.0"
                    
#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.
#:package Pipelines@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pipelines&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Pipelines&version=1.0.0
                    
Install as a Cake Tool

Pipelines

License .NET Standard 2.0 .NET 8 .NET 9 .NET 10

NuGet Version NuGet Version Downloads

Publish

Pipelines is a lightweight library designed to simplify the implementation of the mediator pattern.

Installation

Isntall the latest package using the method that works for you as provided by the nuget site.

The package includes everything you need, including the generator.

How It Works

  1. Request and Response: Define your requests and responses.
  2. Handlers: Create handlers for your request/response pairs.
  3. Execution: Use the Pipeline class as a mediator to find the appropriate pipeline or inject/create a RequestPipeline, then execute the pipeline for a given request. This executes any behavrios before executing the handler and returns the expected response.
  4. Behaviors: Add behaviors to your pipelines to customize the processing of requests and responses. This allows for additional functionality, such as logging, validation, or performance monitoring. Behavrios can be added to the DI too and will be injected.
  5. Source Generation: The Pipelines.Generator simplifies the development process by generating code for handler registration, pipeline creation, and DI integration.

Implementing a specific interface for requests is optional, but it helps when using Pipeline class as you don't have to provide the generic arguments.

Generated handler registration registers handlers on their interfaces. Requesting an IRequestHandler<object, object> will give you your handler but requesting a RequestPipeline<object, object> will give you a built pipeline with your handler wrapped by any behaviors that could be injected.

Examples

You can also find samples here.

Requests

Declaring request/response/handler:

public class MyRequest : IRequest<MyRequest, MyResponse> // interface here is optional
{
    public string Data { get; set; } = string.Empty;
}

public class MyResponse
{
    public string Result { get; set; } = string.Empty;
}

public class MyHandler : IRequestHandler<MyRequest, MyResponse>
{
    public ValueTask<MyResponse> Handle(MyRequest request)
    {
        return new(new MyResponse { Result = $"Processed: {request.Data}" });
    }
}

DI registration if using Microsoft.Extensions.DependencyInjection

services.AddPipelines(); // adds pipelines to the di
services.AddHandlers(); // adds the assembly handlers to the di

Executing a request from di:

var pipeline = serviceProvider.GetRequiredService<Pipeline>();

// with interface
var response1 = pipeline.Request(new MyRequest { Data = "Hello, World!" });

// without interface
var response2 = pipeline.Request<MyRequest, MyResponse>(new MyRequest { Data = "Hello, World!" });

Streams

Declaring stream request/response/handler:

public class MyStreamRequest : IStreamRequest<MyStreamRequest, string> // interface here is optional
{
    public string Query { get; set; }
}

public class MyStreamHandler : IStreamRequestHandler<MyStreamRequest, string>
{
    public async IAsyncEnumerable<string> Handle(MyStreamRequest request)
    {
        yield return $"Result 1 for {request.Query}";
        yield return $"Result 2 for {request.Query}";
    }
}

DI registration same as Requests

Executing a stream from di:

var pipeline = serviceProvider.GetRequiredService<Pipeline>();

// with interface
await foreach (var result in pipeline.Stream(new MyStreamRequest { Query = "Test" }))
{
    Console.WriteLine(result);
}

// without interface
await foreach (var result in pipeline.Stream<MyStreamRequest, string>(new MyStreamRequest { Query = "Test" }))
{
    Console.WriteLine(result);
}

Build and Test

To build and test the project you need an editor/ide of your choice and the .NET SDK.

Structure

Projects
  • Pipelines: Provides the main contracts to build and execute a pipeline.
  • Pipelines.Generator: Provides per assembly extension method generation for registering pipeline and handler implementations to the DI. Referenced by Pipelines and there is no need to install.
Features
  • Root: Contains the Pipeline class that acts as a mediator, determining which pipeline to execute for a given request backed by an IServiceProvider.
  • Requests: Request (Command, Query) functionality and contracts.
  • Streams: StreamRequest functionality and contracts.

Testing

The project uses TUnit and the code was modeled after Andrew Lock's article Creating a source generator.

  • Pipelines.Generator.Test Generator tests using Verify to validated generated output for each possible case. Each test case has it's files in the Resources folder with a Program.cs file for compilation. it also includes the verify files. The naming convetion is {ClassName}/{MethodName}/Program.cs.
  • Pipelines.Generator.Test.Integration Tests all pipeline classes and the generated code from the generator by trying to immitate day to day use.
  • Pipelines.Generator.Test.Integration.NuGet Executes all integration tests by publishing the package at a local nuget source

All tests can be executed using dotnet (excluding nuget), visual studio (excluding nuget) or better by using cake eg:

  • dotnet cake.cs -c Release -- --target test
  • dotnet cake.cs -c Release -- --target test-nuget
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 is compatible.  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 is compatible.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.1-dev.4 49 8/1/2026
1.0.0 58 7/25/2026
1.0.0-alpha.1 82 5/3/2026
1.0.0-alpha 62 5/1/2026
0.0.0-dev.22 52 7/25/2026