Skip to main content

Validation samples

Validation has separate console and ASP.NET Core sample projects. Each runnable choice owns its description on its Sample or Startup class; Program.cs only selects which one to execute.

Core validation

Run the console project:

dotnet run --project validation/samples/Valiant.Validation.Samples

Select one delegate in Program.cs:

DelegateDemonstratesSource
Basic.Sample.RunAsyncA minimal fluent validator, generated registration, validation, and failure outputBasic
AttributeValidation.Sample.RunAsyncValidation attributes on the model with the generated validator contractAttributeValidation
DependencyInjection.Sample.RunAsyncGenerated registrations, configurable lifetime and defaults, concrete non-default validators, property validators, and metadata providersDependencyInjection
SyncAndAsyncValidation.Sample.RunAsyncSync and async APIs, boolean helpers, and the guard against synchronously invoking an asynchronous validatorSyncAndAsyncValidation
Severity.Sample.RunAsyncError, warning, and information severities, including valid warning-only and information-only resultsSeverity
CompositionAndPaths.Sample.RunAsyncWhole-model composition, reusable property validators, child contexts, collection items, and nested/indexed pathsCompositionAndPaths
FailureHandling.Sample.RunAsyncPer-property fail-fast behavior, result helpers, and ThrowIfFailed()FailureHandling
ControlFlowAndCollections.Sample.RunAsyncCollection and dictionary rules, conditions, switches, indexed validation, and native loopsControlFlowAndCollections

The Catalog folder is shared support code for the advanced scenarios, not an additional selectable sample.

ASP.NET Core validation

Run the web project:

dotnet run --project validation/samples/Valiant.Validation.AspNetCore.Samples

Select one startup in Program.cs:

StartupDemonstratesSource
MinimalApi.StartupTyped and all-parameter Minimal API filters that reject invalid requests before the handler runsMinimalApi
Mvc.StartupAutomatic MVC validation without a validator dependency or manual validation branch in the controllerMvc
ProblemDetails.StartupManual validation converted to HTTP and MVC validation problem-details responsesProblemDetails
OpenApi.StartupGenerated Valiant validation metadata projected into the application's OpenAPI documentOpenApi

The Orders folder contains the shared request models and validator; it is not a startup choice.

The web scenarios are also exercised through WebApplicationFactory, so the sampled registration and HTTP behavior stay covered by the validation test project. See ASP.NET Core and OpenAPI for consumer setup.