PlopyBlopy.MediatoR.Alternative.Lite
1.0.20
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PlopyBlopy.MediatoR.Alternative.Lite --version 1.0.20
NuGet\Install-Package PlopyBlopy.MediatoR.Alternative.Lite -Version 1.0.20
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PlopyBlopy.MediatoR.Alternative.Lite" Version="1.0.20" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PlopyBlopy.MediatoR.Alternative.Lite" Version="1.0.20" />
<PackageReference Include="PlopyBlopy.MediatoR.Alternative.Lite" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PlopyBlopy.MediatoR.Alternative.Lite --version 1.0.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PlopyBlopy.MediatoR.Alternative.Lite, 1.0.20"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=PlopyBlopy.MediatoR.Alternative.Lite&version=1.0.20
#tool nuget:?package=PlopyBlopy.MediatoR.Alternative.Lite&version=1.0.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MediatoR.Alternative.Lite
A simplified alternative to MediatR with core features for request handling and pipeline behavior support.
Features
- 🚀 Minimalistic mediator implementation (Sender + Pipeline)
- 🔗 Middleware-like behavior support (validation, logging, etc.)
- ✅ FluentResults integration for error handling
- 💉 Auto-registration of handlers via DI (Microsoft.Extensions.DependencyInjection)
- 🛠️ Extensible architecture
Quick Start
1. Register Services
services
.AddMediatorAlt() // Auto-registers all IRequestHandlers in the current assembly
// Optional behaviors (registration order = execution order):
.AddMediatorAltLogging() // Logging (outer layer)
.AddMediatorAltFluentValidation(); // Validation (inner layer)
2. Create Request
public record GetUserQuery(int UserId) : IRequest<User>;
3. Implement Handler
public class GetUserHandler : IRequestHandler<GetUserQuery, User>
{
public async Task<Result<User>> Handle(GetUserQuery request, CancellationToken ct)
{
// Return result via FluentResults
return Result.Ok(new User(...));
}
}
4. Usage
public class MyService
{
private readonly ISender _sender;
public MyService(ISender sender) => _sender = sender;
public async Task Execute()
{
var result = await _sender.Send(new GetUserQuery(123));
if (result.IsSuccess)
{
var user = result.Value;
}
else
{
var errors = result.Errors; // Access error list
// Handle errors
}
}
}
Pipeline Behaviors
Validation
- Calling
AddMediatorAltFluentValidation()
auto-registers all validators implementingIValidator<TRequest>
Register validators (FluentValidation):
public class GetUserValidator : AbstractValidator<GetUserQuery>
{
public GetUserValidator()
{
RuleFor(x => x.UserId).GreaterThan(0);
}
}
Custom Behavior
public class TimingBehavior<TRequest, TResponse>
: IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
public async Task<Result<TResponse>> Handle(
TRequest request,
CancellationToken ct,
Func<Task<Result<TResponse>>> next)
{
var sw = Stopwatch.StartNew();
var response = await next();
sw.Stop();
Console.WriteLine($"Execution time: {sw.ElapsedMilliseconds}ms");
return response;
}
}
// Registration with order specification:
services.AddTransient(
typeof(IPipelineBehavior<,>), typeof(TimingBehavior<,>)); // Executes after other registered behaviors
Implementation Details
Execution Order
Behaviors execute in registration order:
[Behavior 1] -> [Behavior 2] -> ... -> [Handler]
Example for .AddLogging().AddValidation()
:
[Logging] -> [Validation] -> [Handler]
Key Implementation Notes
- Handlers (
IRequestHandler<,>
) are registered as Scoped - Behaviors (
IPipelineBehavior<,>
) execute in registration order - All errors are aggregated via
FluentResults.Result
Best Practices
- One request - one handler
- Use
Result<T>
(FluentResults) for data returns - Separate concerns:
- Validation → in ValidationBehavior
- Business rules → in handlers
- Cross-cutting concerns → in PipelineBehaviors
- Register behaviors in required order
- Handle errors via
result.Errors
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- FluentResults (>= 3.16.0)
- FluentResults.Errors (>= 1.0.4)
- FluentValidation (>= 11.11.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.