ZeroAlloc.Pipeline.Generators 0.1.2

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

ZeroAlloc.Pipeline

NuGet NuGet CI License: MIT

ZeroAlloc.Pipeline is the shared building block for pipeline-aware source generators in the ZeroAlloc ecosystem. It provides the IPipelineBehavior marker interface, PipelineBehaviorAttribute, and the Roslyn-based discovery, validation, and code-emission utilities that generators like ZeroAlloc.Mediator and ZeroAlloc.Validation build on. All pipeline wiring is resolved at compile time — no reflection, no virtual dispatch, no heap allocation per call.

Install

dotnet add package ZeroAlloc.Pipeline
dotnet add package ZeroAlloc.Pipeline.Generators
<PackageReference Include="ZeroAlloc.Pipeline" Version="*" />
<PackageReference Include="ZeroAlloc.Pipeline.Generators" Version="*"
                  OutputItemType="Analyzer"
                  ReferenceOutputAssembly="false" />

Example

using ZeroAlloc.Pipeline;

// 1. Implement IPipelineBehavior and decorate with [PipelineBehavior]
[PipelineBehavior(Order = 1)]
public class LoggingBehavior : IPipelineBehavior
{
    // 2. Expose a public static Handle method matching the host framework's delegate shape
    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;
    }
}

// 3. The host generator (e.g. ZeroAlloc.Mediator) picks this up at compile time
//    and wires it into the generated pipeline — no registration required.

Performance

ZeroAlloc.Pipeline emits static nested lambda chains. Static lambdas carry no closure allocation, and the JIT inlines static call chains aggressively — collapsing N behaviors into straight-line code.

1 behavior 3 behaviors 5 behaviors Allocated
Static chain 4.1 ns 2.3 ns 2.8 ns 0 B
Pre-built delegate chain 2.2 ns 9.9 ns 17.6 ns 0 B
Speedup 0.5× 4.3× 6.4×

BenchmarkDotNet v0.15.8, .NET 10.0.4, 12th Gen Intel Core i9-12900HK — tests/ZeroAlloc.Pipeline.Benchmarks

Features

  • IPipelineBehavior — marker interface; no contract imposed on Handle signature
  • PipelineBehaviorAttributeOrder (execution position) and AppliesTo (type scoping)
  • Attribute subclassing — framework packages define their own alias; discovery follows the inheritance chain
  • Compile-time discoveryPipelineBehaviorDiscoverer and FromAttributeSyntaxContext for incremental generators
  • Static emitterPipelineEmitter.EmitChain generates a nested static lambda chain from a behavior list and a PipelineShape
  • PipelineShape — describes type arguments, parameter names, and the innermost body; supports a factory delegate when the body embeds depth-indexed lambda names
  • Diagnostic helpersPipelineDiagnosticRules.FindMissingHandleMethod and FindDuplicateOrders return offending behaviors; the caller maps them to framework-specific diagnostic IDs
  • Zero allocation — no reflection, no boxing, no delegate list per call
  • netstandard2.0 + Native AOT — works in trimmed, ahead-of-time compiled applications

Documentation

Page Description
Getting Started Write your first behavior and see it get picked up
Pipeline Behaviors IPipelineBehavior, PipelineBehaviorAttribute, ordering, scoping
Pipeline Shape Describe the delegate shape for code generation
Pipeline Emitter Generate a nested static lambda call chain
Pipeline Discoverer Discover behaviors at compile time
Diagnostics ZAP001, ZAP002 diagnostic rules reference
Performance Why static lambda chains allocate nothing
Testing Test behaviors and generators built on this library

License

MIT

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 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. 
.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
0.1.2 34 3/17/2026
0.1.1 59 3/17/2026