MiniValidation 0.6.0-pre.20220527.55
See the version list below for details.
dotnet add package MiniValidation --version 0.6.0-pre.20220527.55
NuGet\Install-Package MiniValidation -Version 0.6.0-pre.20220527.55
<PackageReference Include="MiniValidation" Version="0.6.0-pre.20220527.55" />
paket add MiniValidation --version 0.6.0-pre.20220527.55
#r "nuget: MiniValidation, 0.6.0-pre.20220527.55"
// Install MiniValidation as a Cake Addin #addin nuget:?package=MiniValidation&version=0.6.0-pre.20220527.55&prerelease // Install MiniValidation as a Cake Tool #tool nuget:?package=MiniValidation&version=0.6.0-pre.20220527.55&prerelease
MiniValidation
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.
Installation
Install the library from NuGet:
❯ dotnet add package MiniValidation --prerelease
ASP.NET Core 6+ Projects
If installing into an ASP.NET Core 6+ project, consider using the MinimalApis.Extensions package instead, which adds extensions specific to ASP.NET Core:
❯ dotnet add package MinimalApis.Extensions --prerelease
Example usage
Console app
using System;
using System.ComponentModel.DataAnnotations;
using MiniValidation;
var title = args.Length > 0 ? args[0] : "";
var widget = new Widget { Name = title };
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 : IValidatableObject
{
[Required, MinLength(3)]
public string Name { get; set; }
public override string ToString() => Name;
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (string.Equals(Name, "Widget", StringComparison.OrdinalIgnoreCase))
{
yield return new("Cannot name a widget 'Widget'.", new [] { nameof(Name) });
}
}
}
❯ widget.exe
Widget has errors!
Name:
- The Name field is required.
❯ widget.exe Ok
Widget has errors!
Name:
- The field Name must be a string or array type with a minimum length of '3'.
❯ widget.exe Widget
Widget has errors!
Name:
- Cannot name a widget 'Widget'.
❯ widget.exe MiniValidation
Widget 'MiniValidation' is valid!
Web app (.NET 6)
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.Run();
class Widget : IValidatableObject
{
[Required, MinLength(3)]
public string? Name { get; set; }
public override string? ToString() => Name;
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (string.Equals(Name, "Widget", StringComparison.OrdinalIgnoreCase))
{
yield return new("Cannot name a widget 'Widget'.");
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- No dependencies.
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 5.0.0)
-
net6.0
- No dependencies.
NuGet packages (18)
Showing the top 5 NuGet packages that depend on MiniValidation:
Package | Downloads |
---|---|
Indice.AspNetCore
Package Description |
|
MinimalApis.Extensions
A set of extensions and helpers for working with ASP.NET Core Minimal APIs. |
|
MinApiLib.Validation
Data annotations validation filter for Minimal API |
|
Hive.Abstractions
Base abstractions for Hive |
|
Wcz.Layout
Package Description |
GitHub repositories (4)
Showing the top 4 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
|
|
DamianEdwards/MinimalApis.Extensions
A set of extensions and helpers for working with ASP.NET Core Minimal APIs.
|
|
marcominerva/MinimalHelpers
A collection of helpers libraries for Minimal API projects.
|
Version | Downloads | Last updated |
---|---|---|
0.9.1 | 117,485 | 4/22/2024 |
0.9.0 | 161,854 | 10/15/2023 |
0.8.0 | 248,660 | 6/22/2023 |
0.7.4 | 64,307 | 3/17/2023 |
0.7.3 | 1,125 | 3/14/2023 |
0.7.2 | 50,003 | 12/21/2022 |
0.7.1 | 1,125 | 12/20/2022 |
0.7.0 | 23,051 | 11/29/2022 |
0.6.0-pre.20220527.55 | 66,602 | 5/27/2022 |
0.5.1-pre.20220429.53 | 6,454 | 4/29/2022 |
0.5.0-pre.20220315.50 | 19,743 | 3/15/2022 |
0.4.2-pre.20220306.48 | 2,316 | 3/6/2022 |
0.4.1-pre.20220107.41 | 9,855 | 1/7/2022 |
0.4.0-pre.20211110.38 | 29,414 | 11/10/2021 |
0.3.0-pre.20210927201159.35 | 2,450 | 9/27/2021 |
0.2.0-pre.20210920234953.30 | 1,908 | 9/20/2021 |