WebApiSkeleton.Contracts.Validation 1.1.1

dotnet add package WebApiSkeleton.Contracts.Validation --version 1.1.1                
NuGet\Install-Package WebApiSkeleton.Contracts.Validation -Version 1.1.1                
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="WebApiSkeleton.Contracts.Validation" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WebApiSkeleton.Contracts.Validation --version 1.1.1                
#r "nuget: WebApiSkeleton.Contracts.Validation, 1.1.1"                
#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.
// Install WebApiSkeleton.Contracts.Validation as a Cake Addin
#addin nuget:?package=WebApiSkeleton.Contracts.Validation&version=1.1.1

// Install WebApiSkeleton.Contracts.Validation as a Cake Tool
#tool nuget:?package=WebApiSkeleton.Contracts.Validation&version=1.1.1                

WebApiSkeleton.Contracts.Validation

WebApiSkeleton.Contracts.Validation contains MediatR PipelineBehavior implementation to validate incoming requests that implement IValidatableRequest using FluentValidation

Usage

Steps to add contract validation:

  • Create validators that are inherited from AbstractValidator<T> for needed requests
  • Use AddContractValidatorsFromAssembly (or AddValidatorsFromAssembly from FluentValidation) to add validators to DI
  • Add validation behaviors for requests in DI
    • One way is to call AddValidationPipelineBehaviorsFromAssembly that will automatically search for classes that are inherited from AbstractValidator and add ValidationBehavior for requests that are passed as a generic parameter in DI. If any of these requests are not returning the Result<A> type the InvalidOperationException is thrown.
      • NOTE: in this case ValidationBehavior for request is automatically added, so it is highly recommended to mind the order of IPipelineBehavior implementations added in DI.
    • Another way is to create ValidationBehavior implementations by calling ValidationBehaviorCreator.GetValidationPipelineBehaviorForRequest method and then add it manually to DI by passing the pipelineBehavior as a service type and validationBehavior as implementation type. This way order of pipeline behaviors executed for each request is handled more clearly by the user, which is adding them.

Example

Example usage shown in Example project

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on WebApiSkeleton.Contracts.Validation:

Package Downloads
WebApiSkeleton.FileSystem.MinIO

Package containing implementation of file system based on Minio S3 storage.

WebApiSkeleton.Security

Package containing security core implementation that is based on MediatR and other WebApiSkeleton MediatR-related packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 136 4/21/2024
1.1.0 110 4/21/2024