Mab.PipelineFramework.SourceGenerator
1.0.2
dotnet add package Mab.PipelineFramework.SourceGenerator --version 1.0.2
NuGet\Install-Package Mab.PipelineFramework.SourceGenerator -Version 1.0.2
<PackageReference Include="Mab.PipelineFramework.SourceGenerator" Version="1.0.2"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Mab.PipelineFramework.SourceGenerator" Version="1.0.2" />
<PackageReference Include="Mab.PipelineFramework.SourceGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Mab.PipelineFramework.SourceGenerator --version 1.0.2
#r "nuget: Mab.PipelineFramework.SourceGenerator, 1.0.2"
#:package Mab.PipelineFramework.SourceGenerator@1.0.2
#addin nuget:?package=Mab.PipelineFramework.SourceGenerator&version=1.0.2
#tool nuget:?package=Mab.PipelineFramework.SourceGenerator&version=1.0.2
PipelineFramework.SourceGenerator
Compile-time source generator for PipelineFramework providing 27.4x performance improvement over reflection-based execution.
Performance Benefits
Verified by BenchmarkDotNet on .NET 8.0:
| Metric | Reflection | Source Generator | Improvement |
|---|---|---|---|
| Execution Time | 42.194 ns | 1.542 ns | 27.4x faster ⚡ |
| Allocations | 88 bytes | 0 bytes | Zero allocations 💚 |
| Std Deviation | ±0.518 ns | ±0.042 ns | 12x more consistent 📊 |
Quick Start
1. Install Package
dotnet add package PipelineFramework.SourceGenerator
2. Mark Your Pipeline Class
Add the [GeneratePipeline] attribute and make your class partial:
using Pipeline.Attributes;
[GeneratePipeline] // 👈 Add this
public partial class OrderPipelineEvents : PipelineEvents // 👈 Add 'partial'
{
[PipelineEvent(Order = 1)]
public PipelineContextAsync<OrderContext>? ValidateOrder { get; set; }
[PipelineEvent(Order = 2, TimeoutMilliseconds = 5000)]
public PipelineContextAsync<OrderContext>? ProcessPayment { get; set; }
}
3. Build and Use
dotnet build
The source generator automatically creates optimized methods:
// Use generated methods - NO REFLECTION! ⚡
await events.ExecuteAllAsync(context);
await events.ExecuteAsync("ValidateOrder", context);
bool hasSubscribers = events.HasSubscribers("ProcessPayment");
string[] eventNames = OrderPipelineEvents.GetEventNames();
Features
- ⚡ 27.4x faster execution than reflection
- 💚 Zero allocations - no garbage collection overhead
- ✅ Compile-time safety - catch errors during build
- 🔍 Better debugging - see and step through generated code
- 🎯 100% optional - works alongside reflection-based code
- ⏱️ Timeout support - automatic timeout handling for events
- 🔀 Mixed sync/async - supports both synchronous and asynchronous events
Generated Methods
The source generator creates these methods for you:
ExecuteAll() / ExecuteAllAsync()
Executes all events in order with direct invocation:
await events.ExecuteAllAsync(context);
Execute(name) / ExecuteAsync(name)
Execute specific events by name:
await events.ExecuteAsync("ValidateOrder", context);
HasSubscribers(name)
Check if an event has subscribers:
bool hasValidation = events.HasSubscribers("ValidateOrder");
GetEventNames()
Get all event names at compile time:
string[] events = OrderPipelineEvents.GetEventNames();
Advanced Features
Timeout Handling
Events with TimeoutMilliseconds get automatic timeout handling:
[PipelineEvent(Order = 1, TimeoutMilliseconds = 5000)]
public PipelineContextAsync<OrderContext>? ProcessPayment { get; set; }
Skip If Cancelled
Events marked with SkipIfCancelled are automatically skipped:
[PipelineEvent(Order = 3, SkipIfCancelled = true)]
public PipelineContextAsync<OrderContext>? SendNotification { get; set; }
Requirements
- .NET 8.0 or higher
- PipelineFramework.Core 1.0.0 or higher
Documentation
License
MIT License - see LICENSE for details
Support
- GitHub Issues: https://github.com/mabouchalkha/pipeline-framework/issues
- Tag:
source-generator
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.0 - Initial stable release
- 27.4x faster execution than reflection (verified by BenchmarkDotNet)
- Zero memory allocations vs 88 bytes per reflection invocation
- Compile-time code generation for ExecuteAll, Execute, HasSubscribers methods
- Support for timeout handling and conditional execution
- Mixed sync/async event support
- Full debugging support with visible generated code
- 100% optional and backward compatible