How lawrence-laz/generic-pipeline works
Project Type and Purpose
• This is a .NET class‐library (NuGet package) called “GenericPipeline” that implements a high-performance, dependency-free pipeline (chain of responsibility) builder supporting both sync and async execution.
• It provides interfaces (IRequest, IRequestHandler, IRequestHandlerAsync), a Pipeline builder, a set of built-in Behaviors (e.g., MediatorBehavior, SingleHandlerBehavior, UnhandledThrowingBehavior), extension methods for configuration and DI integration, plus examples, benchmarks, and tests.
File Structure Analysis
• src/GenericPipeline: Core library project
• Behaviors/…: Sync and async behaviors and their handler implementations
• Internal/…: low-level pipeline wiring & DI support (ServiceProviderExtensions, RequestHandlers)
• Pipeline.cs / PipelineAsync.cs: builder types for sync/async pipelines
• PipelineBehavior(Async).cs: behavior delegate definitions
• PipelineExtensions(Async).cs: fluent configuration APIs
• GenericPipeline.csproj, IRequest*.cs, Unit.cs, Exceptions.cs, Usings.cs
• examples/: Consumer applications demonstrating how to wire up and use the library (ExceptionHandling, FluentValidation, Mediator, Polly, Serilog)
• test/:
• GenericPipeline.Tests: unit tests covering behaviors, pipeline functionality
• GenericPipeline.Benchmarks: BenchmarkDotNet scenarios comparing performance vs. other libraries
• .github/workflows/: CI build and publish pipelines
• readme.md, LICENSE.md, images/: project description and assets
README Insights
• Emphasizes zero external dependencies, high performance (no allocations), support for DI and non-DI modes, sync/async behaviors, runtime behavior/handler changes.
• Benchmarks quantify per-invocation overhead vs. MediatR, PipelineNet, etc.
1. Core Interfaces
• IRequest<TResponse>
• IRequestHandler<TRequest,TResponse> / IRequestHandlerAsync
2. Pipeline Builder
• Pipeline<TRequest,TResponse> / PipelineAsync<TRequest,TResponse>
3. Behaviors (Chain Links)
• PipelineBehavior<TRequest,TResponse> / PipelineBehaviorAsync
• MediatorBehavior / MediatorBehaviorAsync
• SingleHandlerBehavior / …Async
• UnhandledThrowingBehavior / …Async
4. Internal Wiring
• RequestHandlers (method discovery/invocation)
• ServiceProviderExtensions (DI integration)
5. Extension Methods
• PipelineExtensions / PipelineExtensionsAsync for “UseBehavior”, “UseHandler”, “Send”
6. Consumer Layer
• Example applications or host project
• Dependency Injection container (optional)
7. CI/CD & Packaging
• GitHub Actions (Build, Publish)
• NuGet packaging
• Consumer invokes PipelineBuilder (Pipeline.Create or via DI)
• Builder assembles a linked list (chain) of Behavior delegates
• Send(request) flows through Behavior chain → eventually invokes IRequestHandler
• Behaviors call next() to propagate through chain
• Internal RequestHandlers resolve and invoke the correct handler(s)
• If DI is used, ServiceProviderExtensions integrate pipeline builder into Microsoft.Extensions.DependencyInjection
• CI/CD pipelines pick up src and push package to NuGet
c. Architectural Patterns
• Chain of Responsibility (pipeline of behaviors)
• Builder / Fluent API (PipelineExtensions)
• Strategy (handler lookup & invocation)
• Zero-allocation, high-performance focus
d. Key Technologies & Frameworks
• .NET 6+ / .NET Standard
• C# interfaces/generics/delegates
• BenchmarkDotNet (in test/benchmarks)
• xUnit or NUnit (unit tests)
• GitHub Actions for CI & CD