Validly 1.0.0
See the version list below for details.
dotnet add package Validly --version 1.0.0
NuGet\Install-Package Validly -Version 1.0.0
<PackageReference Include="Validly" Version="1.0.0" />
paket add Validly --version 1.0.0
#r "nuget: Validly, 1.0.0"
// Install Validly as a Cake Addin #addin nuget:?package=Validly&version=1.0.0 // Install Validly as a Cake Tool #tool nuget:?package=Validly&version=1.0.0
Validly
This repository contains a powerful, efficient, and highly customizable validation library for .NET, leveraging the capabilities of C# Source Generators to provide compile-time validation logic generation. The library is designed to simplify model validation in .NET applications by automatically generating validation code based on attributes and custom rules, reducing runtime overhead and enhancing code maintainability.
Key Features
- Compile-Time Code Generation: Uses C# Source Generators to create validation code at compile-time, eliminating the need for runtime reflection and improving performance.
- Attribute-Based Validation: Define validation rules using simple attributes directly on your models, allowing clear and maintainable validation rules.
- Property and Object-Level Validation: Supports validation of individual properties as well as the model as a whole, enabling both fine-grained and aggregate validations.
- Customizable Validation Logic: Extend the library with custom validation attributes and rules to meet unique validation requirements.
- Detailed Validation Results: Provides rich validation results, including per-property error messages and model-wide validation summaries.
- Seamless Integration: Designed to work smoothly in .NET applications, with support for dependency injection and easy configuration.
Getting Started
To start using the library, add it to your project as a NuGet package. Decorate your model properties with validation attributes and let the source generator handle the rest. Generated code will include optimized validation methods that you can call to validate instances of your models.
Example Usage
Define validation rules using attributes on your model properties:
[Validatable]
public partial class CreateUserRequest
{
[Required]
[MinLength(3)]
[MaxLength(100)]
public string Name { get; set; }
[Required]
[EmailAddress]
public int Email { get; set; }
[Range(18, 99)]
public int Age { get; set; }
}
Validate the model in your application code:
app.MapPost("/users", async (CreateUserRequest request) =>
{
var validationResult = request.Validate(); // This method is generated by the source generator
if (!validationResult.Valid)
{
return Results.BadRequest(validationResult);
}
// create user...
return Results.Created($"/users/{user.Id}");
});
Installation
Install the package via NuGet:
dotnet add package Validly
Install the source generator package to enable compile-time validation code generation:
dotnet add package Validly.SourceGenerator
Install the package with default validators:
dotnet add package Validly.Validators
Contributions
Contributions are welcome! Feel free to open issues, submit pull requests, or suggest enhancements to improve the library further.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.ObjectPool (>= 8.0.10)
- System.Collections.Immutable (>= 6.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Validly:
Package | Downloads |
---|---|
Validly.SourceGenerator
Source Generator for Validly validation library |
|
Validly.Extensions.Validators
Basic validation rules for Validly |
|
Validly.Extensions.AspNetCore
Validly extensions for ASP.NET Core |
GitHub repositories
This package is not used by any popular GitHub repositories.