![]() |
VOOZH | about |
dotnet add package MiniValidation --version 0.10.0
NuGet\Install-Package MiniValidation -Version 0.10.0
<PackageReference Include="MiniValidation" Version="0.10.0" />
<PackageVersion Include="MiniValidation" Version="0.10.0" />Directory.Packages.props
<PackageReference Include="MiniValidation" />Project file
paket add MiniValidation --version 0.10.0
#r "nuget: MiniValidation, 0.10.0"
#:package MiniValidation@0.10.0
#addin nuget:?package=MiniValidation&version=0.10.0Install as a Cake Addin
#tool nuget:?package=MiniValidation&version=0.10.0Install as a Cake Tool
A minimalistic validation library built atop the existing features in .NET's System.ComponentModel.DataAnnotations namespace. Adds support for single-line validation calls and recursion with cycle detection.
Supports .NET Standard 2.0 compliant runtimes.
Install the library from NuGet:
❯ dotnet add package MiniValidation
If installing into an ASP.NET Core 8+ project, consider using the MinimalApis.Extensions package instead, which adds extensions specific to ASP.NET Core, including a validation endpoint filter:
❯ dotnet add package MinimalApis.Extensions
var widget = new Widget { Name = "" };
var isValid = MiniValidator.TryValidate(widget, out var errors);
class Widget
{
[Required, MinLength(3)]
public string Name { get; set; }
public override string ToString() => Name;
}
var widget = new Widget { Name = "" };
// Get your serviceProvider from wherever makes sense
var serviceProvider = ...
var isValid = MiniValidator.TryValidate(widget, serviceProvider, out var errors);
class Widget : IValidatableObject
{
[Required, MinLength(3)]
public string Name { get; set; }
public override string ToString() => Name;
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var disallowedNamesService = validationContext.GetService(typeof(IDisallowedNamesService)) as IDisallowedNamesService;
if (disallowedNamesService is null)
{
throw new InvalidOperationException($"Validation of {nameof(Widget)} requires an {nameof(IDisallowedNamesService)} instance.");
}
if (disallowedNamesService.IsDisallowedName(Name))
{
yield return new($"Cannot name a widget '{Name}'.", new[] { nameof(Name) });
}
}
}
using System.ComponentModel.DataAnnotations;
using MiniValidation;
var title = args.Length > 0 ? args[0] : "";
var widgets = new List<Widget>
{
new Widget { Name = title },
new WidgetWithCustomValidation { Name = title }
};
foreach (var widget in widgets)
{
if (!MiniValidator.TryValidate(widget, out var errors))
{
Console.WriteLine($"{nameof(Widget)} has errors!");
foreach (var entry in errors)
{
Console.WriteLine($" {entry.Key}:");
foreach (var error in entry.Value)
{
Console.WriteLine($" - {error}");
}
}
}
else
{
Console.WriteLine($"{nameof(Widget)} '{widget}' is valid!");
}
}
class Widget
{
[Required, MinLength(3)]
public string Name { get; set; }
public override string ToString() => Name;
}
class WidgetWithCustomValidation : Widget, IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (string.Equals(Name, "Widget", StringComparison.OrdinalIgnoreCase))
{
yield return new($"Cannot name a widget '{Name}'.", new[] { nameof(Name) });
}
}
}
❯ widget.exe
Widget 'widget' is valid!
Widget has errors!
Name:
- Cannot name a widget 'widget'.
❯ widget.exe Ok
Widget has errors!
Name:
- The field Name must be a string or array type with a minimum length of '3'.
Widget has errors!
Name:
- The field Name must be a string or array type with a minimum length of '3'.
❯ widget.exe Widget
Widget 'Widget' is valid!
Widget has errors!
Name:
- Cannot name a widget 'Widget'.
❯ widget.exe MiniValidation
Widget 'MiniValidation' is valid!
Widget 'MiniValidation' is valid!
using System.ComponentModel.DataAnnotations;
using MiniValidation;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World");
app.MapGet("/widgets", () =>
new[] {
new Widget { Name = "Shinerizer" },
new Widget { Name = "Sparklizer" }
});
app.MapGet("/widgets/{name}", (string name) =>
new Widget { Name = name });
app.MapPost("/widgets", (Widget widget) =>
!MiniValidator.TryValidate(widget, out var errors)
? Results.ValidationProblem(errors)
: Results.Created($"/widgets/{widget.Name}", widget));
app.MapPost("/widgets/custom-validation", (WidgetWithCustomValidation widget) =>
!MiniValidator.TryValidate(widget, out var errors)
? Results.ValidationProblem(errors)
: Results.Created($"/widgets/{widget.Name}", widget));
app.Run();
class Widget
{
[Required, MinLength(3)]
public string? Name { get; set; }
public override string? ToString() => Name;
}
class WidgetWithCustomValidation : Widget, IValidatableObject
{
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (string.Equals(Name, "Widget", StringComparison.OrdinalIgnoreCase))
{
yield return new($"Cannot name a widget '{Name}'.", new[] { nameof(Name) });
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on MiniValidation:
| Package | Downloads |
|---|---|
|
MinimalApis.Extensions
A set of extensions and helpers for working with ASP.NET Core Minimal APIs. |
|
|
Indice.AspNetCore
Package Description |
|
|
Hive.MicroServices
Core orchestration framework for Hive microservices |
|
|
MinApiLib.Validation
Data annotations validation filter for Minimal API |
|
|
Wcz.Layout
Package Description |
Showing the top 6 popular GitHub repositories that depend on MiniValidation:
| Repository | Stars |
|---|---|
|
davidfowl/TodoApp
Todo application with ASP.NET Core Blazor WASM, Minimal APIs and Authentication
|
|
|
exceptionless/Exceptionless
Exceptionless application
|
|
|
json-api-dotnet/JsonApiDotNetCore
A framework for building JSON:API compliant REST APIs using ASP.NET and Entity Framework Core.
|
|
|
Mteheran/api-colombia
Public api that contains info about Colombia, departments, cities, tourists places and presidents
|
|
|
DamianEdwards/MinimalApis.Extensions
A set of extensions and helpers for working with ASP.NET Core Minimal APIs.
|
|
|
marinasundstrom/YourBrand
Prototype enterprise system for e-commerce and consulting services
|
| Version | Downloads | Last Updated |
|---|---|---|
| 0.10.0 | 22,089 | 5/4/2026 |
| 0.9.2 | 701,481 | 12/20/2024 |
| 0.9.1 | 664,442 | 4/22/2024 |
| 0.9.0 | 407,611 | 10/15/2023 |
| 0.8.0 | 772,395 | 6/22/2023 |
| 0.7.4 | 76,655 | 3/17/2023 |
| 0.7.3 | 1,786 | 3/14/2023 |
| 0.7.2 | 89,848 | 12/21/2022 |
| 0.7.1 | 1,781 | 12/20/2022 |
| 0.7.0 | 41,467 | 11/29/2022 |
| 0.6.0-pre.20220527.55 | 77,772 | 5/27/2022 |
| 0.5.1-pre.20220429.53 | 7,166 | 4/29/2022 |
| 0.5.0-pre.20220315.50 | 21,628 | 3/15/2022 |
| 0.4.2-pre.20220306.48 | 2,790 | 3/6/2022 |
| 0.4.1-pre.20220107.41 | 10,957 | 1/7/2022 |
| 0.4.0-pre.20211110.38 | 37,095 | 11/10/2021 |
| 0.3.0-pre.20210927201159.35 | 3,082 | 9/27/2021 |
| 0.2.0-pre.20210920234953.30 | 2,150 | 9/20/2021 |