AspNet.KickStarter.CQRS
1.2.3
Prefix Reserved
dotnet add package AspNet.KickStarter.CQRS --version 1.2.3
NuGet\Install-Package AspNet.KickStarter.CQRS -Version 1.2.3
<PackageReference Include="AspNet.KickStarter.CQRS" Version="1.2.3" />
paket add AspNet.KickStarter.CQRS --version 1.2.3
#r "nuget: AspNet.KickStarter.CQRS, 1.2.3"
// Install AspNet.KickStarter.CQRS as a Cake Addin #addin nuget:?package=AspNet.KickStarter.CQRS&version=1.2.3 // Install AspNet.KickStarter.CQRS as a Cake Tool #tool nuget:?package=AspNet.KickStarter.CQRS&version=1.2.3
AspNet.KickStarter.CQRS
This library provides the following basic interfaces used to implement CQRS with MediatR
ICommand
andICommandHandler
IQuery
andIQueryHandler
These commands and queries rely on Result
, Result<T>
and Error
types from the AspNet.KickStarter.FunctionalResult
library.
TracePipelineBehavior
The library provides a generic TracePipelineBehavior
class that adds automatic trace activities for any commands or queries. This can be registered as follows:
builder.Services
.AddMediatR(_ => _.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()))
.AddTracePipelineBehavior();
ValidationPipelineBehavior
The library provides a generic ValidationPipelineBehavior
class that enables use of FluentValidation for any commands or queries with a corresponding validator class. This can be registered as follows:
builder.Services
.AddMediatR(_ => _.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()))
.AddValidationPipelineBehavior()
.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly(), includeInternalTypes: true);
Sample Usage
public record GetDoubleQuery(double Value) : IQuery<double>;
internal async Task<IResult> GetDoubleAsync(double value)
{
var result = await _mediator.Send(new GetDoubleQuery(value));
return result.Match(
success => Results.Ok(success),
error => error.AsHttpResult());
}
internal class GetDoubleQueryValidator : AbstractValidator<GetDoubleQuery>
{
public GetDoubleQueryValidator()
{
RuleFor(_ => _.Value)
.GreaterThanOrEqualTo(0)
.LessThanOrEqualTo(10);
}
}
internal class GetDoubleQueryHandler : IQueryHandler<GetDoubleQuery, double>
{
public Task<Result<double>> Handle(GetDoubleQuery request, CancellationToken cancellationToken)
{
Result<double> result;
try
{
result = 2 * request.Value;
}
catch (Exception ex)
{
result = ex;
}
return Task.FromResult(result);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- AspNet.KickStarter.FunctionalResult (>= 1.2.3)
- AspNet.KickStarter.Tracing (>= 1.2.3)
- FluentValidation (>= 11.9.1)
- MediatR (>= 12.2.0)
-
net8.0
- AspNet.KickStarter.FunctionalResult (>= 1.2.3)
- AspNet.KickStarter.Tracing (>= 1.2.3)
- FluentValidation (>= 11.9.1)
- MediatR (>= 12.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AspNet.KickStarter.CQRS:
Package | Downloads |
---|---|
AspNet.KickStarter
This simplifies the bootstrapping code to run a minimal API with optional AddIn support for Serilog, FluentValidation, OpenTelemetry and Swagger. |
GitHub repositories
This package is not used by any popular GitHub repositories.