ZeroAlloc.Pipeline 2.0.1

dotnet add package ZeroAlloc.Pipeline --version 2.0.1
                    
NuGet\Install-Package ZeroAlloc.Pipeline -Version 2.0.1
                    
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="ZeroAlloc.Pipeline" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Pipeline" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Pipeline" />
                    
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 ZeroAlloc.Pipeline --version 2.0.1
                    
#r "nuget: ZeroAlloc.Pipeline, 2.0.1"
                    
#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 ZeroAlloc.Pipeline@2.0.1
                    
#: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=ZeroAlloc.Pipeline&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Pipeline&version=2.0.1
                    
Install as a Cake Tool

ZeroAlloc.Pipeline

NuGet Build codecov License: MIT AOT GitHub Sponsors

Compile-time pipeline behaviors for .NET source generators: behaviors are discovered at build time and emitted as a static call chain, with no reflection, no allocation per call, and NativeAOT support.

It is the building block behind the pipelines of ZeroAlloc.Mediator and ZeroAlloc.Validation. Write a behavior once against its contracts, or use its Roslyn helpers to give your own generator the same pipeline.

Why ZeroAlloc.Pipeline

  • No allocation per call. An emitted three-behavior chain is compiled and asserted at 0 B per call with AllocationGate on every test run. A chain that reads instance state passes it through every level as state, so its lambdas stay static and it is also asserted at 0 B per call.
  • Faster as the pipeline grows. In the same benchmark run, a pre-built delegate chain takes 4.24× the time of the static chain at 3 behaviors and 3.72× at 5. With a single behavior the two are level; see Performance.
  • Works under NativeAOT and trimming. The contracts package is IsAotCompatible, and CI publishes and runs a NativeAOT smoke app on every build. The pipeline is plain static calls, so the trimmer has nothing to keep alive.
  • Mistakes caught at build time. Rule helpers find a missing or invalid Handle method, duplicate Order values, and a [PipelineBehavior] class that forgot IPipelineBehavior; your generator reports them as compiler diagnostics instead of a pipeline that silently skips a step.

Install

Writing behaviors for a host such as ZeroAlloc.Mediator? You need only the contracts:

dotnet add package ZeroAlloc.Pipeline

Building your own pipeline-aware generator? Add the Roslyn helper library as a private dependency and ship ZeroAlloc.Pipeline.Generators.dll next to your generator, as described in Getting Started:

<PackageReference Include="ZeroAlloc.Pipeline.Generators" Version="2.*" PrivateAssets="all" />

Quick start

A behavior is a class with a static Handle method. The host generator finds it at compile time and calls it directly; there is nothing to register.

using System;
using System.Threading;
using System.Threading.Tasks;
using ZeroAlloc.Pipeline;

[PipelineBehavior(Order = 1)]
public class LoggingBehavior : IPipelineBehavior
{
    public static async ValueTask<TResponse> Handle<TRequest, TResponse>(
        TRequest request,
        CancellationToken ct,
        Func<TRequest, CancellationToken, ValueTask<TResponse>> next)
    {
        Console.WriteLine($"Handling {typeof(TRequest).Name}");
        var response = await next(request, ct);
        Console.WriteLine($"Handled {typeof(TRequest).Name}");
        return response;
    }
}

Inside a generator, PipelineEmitter turns the discovered behaviors into the call chain:

using ZeroAlloc.Pipeline.Generators;

PipelineBehaviorInfo[] behaviors =
[
    new("global::App.AuthBehavior", order: 1, appliesTo: null, typeParamCount: 2),
    new("global::App.LoggingBehavior", order: 2, appliesTo: null, typeParamCount: 2),
];

var shape = new PipelineShape
{
    TypeArguments = ["global::App.Ping", "string"],
    OuterParameterNames = ["request", "ct"],
    LambdaParameterPrefixes = ["r", "c"],
    InnermostBodyFactory = depth => $"global::App.PingHandler.Handle(r{depth}, c{depth})",
};

string chain = PipelineEmitter.EmitChain(behaviors, shape);
// global::App.AuthBehavior.Handle<global::App.Ping, string>(request, ct, static (r1, c1) =>
//     global::App.LoggingBehavior.Handle<global::App.Ping, string>(r1, c1, static (r2, c2) =>
//         global::App.PingHandler.Handle(r2, c2)))

When the innermost body needs instance state, such as a scope's IServiceProvider, set State = new PipelineState { TypeName = "global::System.IServiceProvider", Argument = "_services" }. The emitter passes it through every level as the second argument, so the lambdas stay static and the behaviors take it as a last type parameter, Handle<TRequest, TResponse, TState>. See Pipeline Shape.

What you get

  • Behavior contracts: IPipelineBehavior and [PipelineBehavior], with ordering and scoping a behavior to one request type through AppliesTo.
  • Your own attribute name: host frameworks subclass [PipelineBehavior], and discovery follows the inheritance chain.
  • Incremental discovery: finds behaviors from ForAttributeWithMetadataName or a whole compilation.
  • Chain emission: static lambda chains, with an optional state slot for bodies that read instance state.
  • Reusable rules: the three validation checks above, mapped to your generator's own diagnostic IDs.

Performance

The static chain that PipelineEmitter.EmitChain generates, against a delegate chain built once at startup, the fastest runtime-composed alternative. Ratio is mean time relative to the static chain in the same run; lower is faster.

Behaviors Static chain Pre-built delegate chain Allocated, both
1 1.00 1.03 0 B
3 1.00 4.24 0 B
5 1.00 3.72 0 B

BenchmarkDotNet v0.15.8, .NET 10.0.13, three launches; allocations are exact. Full results, method and caveats: docs/performance.md.

Learn more

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on ZeroAlloc.Pipeline:

Package Downloads
ZeroAlloc.Mediator

A zero-allocation mediator library for .NET. Roslyn source generator wires all dispatch at compile time — no reflection, no dictionaries, no virtual dispatch.

ZeroAlloc.Validation

A zero-allocation validation library for .NET. Roslyn source generator wires all rule evaluation at compile time — no reflection, no boxing, no runtime overhead.

Rag.NET

Modular RAG pipeline library for .NET — ingestion and retrieval pipeline builders, self-query, corrective RAG and conversation memory

ZeroAlloc.Saga

Source-generated long-running process orchestration. Multi-step sagas with compensation, FSM via ZeroAlloc.StateMachine, dispatch via ZeroAlloc.Mediator. Native AOT compatible.

ZeroAlloc.Saga.Outbox

Transactional outbox bridge for ZeroAlloc.Saga — command dispatch committed atomically with the saga state save on EF Core, on Redis with ZeroAlloc.Saga.Outbox.Redis, and on ZeroAlloc.ORM with ZeroAlloc.Saga.Outbox.Orm.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 93 11/22/2026
2.0.0 401 11/22/2026
1.5.2 627 11/23/2026
1.5.1 3,377 11/17/2026
1.5.0 6,314 11/11/2026
1.4.4 10,370 10/21/2026
1.4.3 1,975 10/18/2026
1.4.2 1,819 10/16/2026
1.4.1 1,281 10/15/2026
1.4.0 81,773 9/30/2026
1.3.0 1,776 9/30/2026
1.2.5 1,908 9/28/2026
1.2.4 3,049 9/20/2026
1.2.3 433 9/20/2026
1.2.2 52,647 9/19/2026
1.2.1 2,668 5/12/2026
1.2.0 13,664 5/3/2026
1.1.0 178 5/1/2026
1.0.1 172 4/29/2026
1.0.0 179 4/28/2026
Loading failed