MediatR.Extensions.FluentValidation.AspNetCore
3.0.0
.NET Standard 2.1
Install-Package MediatR.Extensions.FluentValidation.AspNetCore -Version 3.0.0
dotnet add package MediatR.Extensions.FluentValidation.AspNetCore --version 3.0.0
<PackageReference Include="MediatR.Extensions.FluentValidation.AspNetCore" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MediatR.Extensions.FluentValidation.AspNetCore --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MediatR.Extensions.FluentValidation.AspNetCore, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MediatR.Extensions.FluentValidation.AspNetCore as a Cake Addin
#addin nuget:?package=MediatR.Extensions.FluentValidation.AspNetCore&version=3.0.0
// Install MediatR.Extensions.FluentValidation.AspNetCore as a Cake Tool
#tool nuget:?package=MediatR.Extensions.FluentValidation.AspNetCore&version=3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MediatR.Extensions.FluentValidation.AspNetCore
MediatR extension for FluentValidation using asp.net core
Install
A priori you need to install packages Mediatr and FluentValidation then continue below
Install with nuget
Install-Package MediatR.Extensions.FluentValidation.AspNetCore
Install with .NET CLI
dotnet add package MediatR.Extensions.FluentValidation.AspNetCore
How to use
Setup - Add configuration in startup
public void ConfigureServices(IServiceCollection services)
{
// Add framework services etc.
services.AddMvc();
var domainAssembly = typeof(GenerateInvoiceHandler).GetTypeInfo().Assembly;
// Add MediatR
services.AddMediatR(domainAssembly);
//Add FluentValidation
services.AddFluentValidation(new[] {domainAssembly});
//Add other stuffs
...
}
Use
Just to write down validators for IRequest
implementation. Validation will be executed before handling IRequestHandler
.
public class GenerateInvoiceValidator : AbstractValidator<GenerateInvoiceRequest>
{
public GenerateInvoiceValidator()
{
RuleFor(x => x.Month).LowerThan(13);
// etc.
}
}
public class GenerateInvoiceRequest : IRequest
{
public int Month { get; set; }
}
public class GenerateInvoiceRequestHandler : IRequestHandler<GenerateInvoiceRequest>
{
public async Task<Unit> Handle(GenerateInvoiceRequest request, CancellationToken cancellationToken)
{
// request data has been validated
...
}
}
More examples check FluentValidation docs: https://fluentvalidation.net/start
Product | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.1 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- FluentValidation (>= 11.0.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.0.0)
- MediatR (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MediatR.Extensions.FluentValidation.AspNetCore:
Package | Downloads |
---|---|
Kros.CqrsTemplate
Package Description |
|
Atlas.Framework.CleanArchitecture
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.