RA.Utilities.Feature
· 2 min read
Version 10.0.0-rc.2
This release modernizes the RA.Utilities.Feature package, providing a foundational toolkit for implementing the Vertical Slice Architecture pattern using CQRS. It offers base handlers, validation behaviors, and seamless integration with the Result<T> type to streamline feature development.
✨ New Features & Improvements
-
Base Handlers for CQRS:
- Provides abstract base classes (
BaseHandler<TRequest, TResponse>) that encapsulate common logic like logging and exception handling. - Handlers automatically catch exceptions and wrap them in a
Result.Failure, ensuring robust error handling without boilerplatetry-catchblocks.
- Provides abstract base classes (
-
Automatic Validation Pipeline Behavior:
- Includes a
ValidationBehavior<TRequest, TResponse>for MediatR pipelines. - Automatically intercepts incoming requests, finds the corresponding
FluentValidationvalidator, and executes it. - If validation fails, the pipeline is short-circuited, and a
Result.Failurecontaining aValidationExceptionis returned immediately, preventing invalid data from reaching your business logic.
- Includes a
-
Seamless
Result<T>Integration:- Designed from the ground up to work with the
Result<T>type fromRA.Utilities.Core, promoting explicit and predictable error handling for business logic failures.
- Designed from the ground up to work with the
-
Updated Documentation:
- The
README.mdhas been updated to provide a clear, step-by-step guide for creating a complete feature slice, including the command, validator, handler, and DI registration.
- The
🚀 Getting Started
Register MediatR, the validation behavior, and your validators in Program.cs:
var builder = WebApplication.CreateBuilder(args);
// 1. Add MediatR and register handlers
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
// 2. Add the validation pipeline behavior from this package
builder.Services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
// 3. Scan and register all FluentValidation validators
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());