Search for a command to run...

Hakim.Pipelines is a .NET library that packages the MediatR pipeline behaviours a CQRS project otherwise rewrites by hand β request logging, performance warnings, FluentValidation integration, transaction management, and response caching β as tested, configurable components. Its distinguishing component is a Result-based validation behaviour: validation failures returned as values rather than thrown as exceptions. Current release 0.1.0 (MIT), targeting .NET 8 and MediatR 12.
The behaviours are small, but they are rewritten in nearly every mediator-based project, and each rewrite re-decides the same questions β in which order behaviours compose, when a transaction commits, whether invalid input is an exception β with slightly different answers and usually without tests. The validation question is the consequential one. The conventional template throws a ValidationException for invalid input, which treats an expected, routine outcome (a user submitted a bad form) as an exceptional control flow, and forces every caller into exception handling for a case that is part of the domain. The behaviours in this package were extracted from my own projects, where they had already been through that rewriting cycle β the final copy ran in this site's backend.
Marker interfaces, not configuration sprawl. A behaviour engages only where it has work: transactions wrap requests marked ITransactionalRequest, caching serves requests marked ICacheableRequest and evicts on ICacheInvalidatorRequest, validation runs only where a validator is registered. A component with nothing to do is inert β if no IUnitOfWork is registered, the transaction behaviour does nothing rather than failing.
Composition order is fixed and documented. Unhandled-exception logging wraps all other behaviours; then logging, performance, validation, transaction, caching, and finally the handler. Order is semantics in a pipeline β validation before transaction means an invalid request never opens a unit of work β so the order is a stated contract, not an accident of registration.
Both validation semantics, one switch. Throwing validation (ValidationException, handler never executes) for codebases built on that convention; Result-based validation for codebases that model expected failures as values. The bundled Result / Result<T> type is deliberately minimal (IsSuccess / IsFailure, Errors, Value, and factories) β the point is the control flow, not a framework.
The package ships a sample application that exercises the pipeline end to end. Actual output, abridged at the marked points. A valid transactional command β the unit of work opens and commits around the handler:
The same command with an empty name and a negative price, under Result-based validation β no exception is thrown and the handler is never invoked:
Caching and invalidation β the second read is served from cache (0 ms, handler not executed); a later command evicts the key only after completing successfully:
All options are set through AddPipelines(options => ...): EnableUnhandledException, EnableLogging, EnablePerformance (with PerformanceThreshold, default 500 ms), EnableValidation, EnableResultValidation (mutually exclusive with the throwing behaviour), EnableTransaction, and EnableCaching (with DefaultCacheDuration, default 5 minutes).
Version 0.1.0 β a first, deliberately small release: the behaviour set is the one extracted from production-shaped code of my own, no more. Requirements: .NET 8, MediatR 12.x (the last open-source MediatR release line), FluentValidation 11.x.