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
<PackageReference Include="ZeroAlloc.Pipeline.Generators" Version="0.1.2" />
<PackageVersion Include="ZeroAlloc.Pipeline.Generators" Version="0.1.2" />
<PackageReference Include="ZeroAlloc.Pipeline.Generators" />
paket add ZeroAlloc.Pipeline.Generators --version 0.1.2
#r "nuget: ZeroAlloc.Pipeline.Generators, 0.1.2"
#:package ZeroAlloc.Pipeline.Generators@0.1.2
#addin nuget:?package=ZeroAlloc.Pipeline.Generators&version=0.1.2
#tool nuget:?package=ZeroAlloc.Pipeline.Generators&version=0.1.2
ZeroAlloc.Pipeline
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 signaturePipelineBehaviorAttribute—Order(execution position) andAppliesTo(type scoping)- Attribute subclassing — framework packages define their own alias; discovery follows the inheritance chain
- Compile-time discovery —
PipelineBehaviorDiscovererandFromAttributeSyntaxContextfor incremental generators - Static emitter —
PipelineEmitter.EmitChaingenerates a nested static lambda chain from a behavior list and aPipelineShape PipelineShape— describes type arguments, parameter names, and the innermost body; supports a factory delegate when the body embeds depth-indexed lambda names- Diagnostic helpers —
PipelineDiagnosticRules.FindMissingHandleMethodandFindDuplicateOrdersreturn 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 | Versions 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. |
-
.NETStandard 2.0
- ZeroAlloc.Pipeline (>= 0.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.