FlexValidator 1.0.1
dotnet add package FlexValidator --version 1.0.1
NuGet\Install-Package FlexValidator -Version 1.0.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="FlexValidator" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlexValidator" Version="1.0.1" />
<PackageReference Include="FlexValidator" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FlexValidator --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FlexValidator, 1.0.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.
#:package FlexValidator@1.0.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FlexValidator&version=1.0.1
#tool nuget:?package=FlexValidator&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FlexValidator
A flexible and powerful validation library for .NET applications with fluent API support.
🚀 Features
- Fluent API: Easy-to-use and readable validation rules
- Async Support: Full async/await support for validation
- Extensible: Easy to extend with custom validators
- Performance: Optimized for high-performance scenarios
- Localization: Support for custom error messages and localization
- Integration: Works seamlessly with ASP.NET Core, Blazor, and other .NET frameworks
📦 Installation
Install via NuGet Package Manager:
Install-Package FlexValidator
Or via .NET CLI:
dotnet add package FlexValidator
🎯 Quick Start
Basic Usage
using FlexValidator;
public class Customer
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
public class CustomerValidator : AbstractValidator<Customer>
{
public CustomerValidator()
{
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage("Name is required");
RuleFor(x => x.Age)
.GreaterThan(0)
.WithMessage("Age must be greater than 0");
RuleFor(x => x.Email)
.NotEmpty()
.WithMessage("Email is required");
}
}
// Usage
var validator = new CustomerValidator();
var customer = new Customer { Name = "John", Age = 30, Email = "john@example.com" };
var result = validator.Validate(customer);
if (result.IsValid)
{
Console.WriteLine("Customer is valid!");
}
else
{
foreach (var error in result.Errors)
{
Console.WriteLine($"Error: {error.ErrorMessage}");
}
}
Async Validation
var result = await validator.ValidateAsync(customer);
Inline Validation
var validator = new InlineValidator<Customer>();
validator.RuleFor(x => x.Name).NotEmpty();
validator.RuleFor(x => x.Age).GreaterThan(0);
var result = validator.Validate(customer);
🔧 Advanced Usage
Custom Validators
public class CustomerValidator : AbstractValidator<Customer>
{
public CustomerValidator()
{
RuleFor(x => x.Email)
.Must(BeValidEmail)
.WithMessage("Please enter a valid email address");
}
private bool BeValidEmail(string email)
{
// Custom email validation logic
return !string.IsNullOrEmpty(email) && email.Contains("@");
}
}
Conditional Validation
RuleFor(x => x.Age)
.GreaterThan(18)
.When(x => x.IsAdult);
Child Object Validation
RuleFor(x => x.Address)
.ChildRules(address =>
{
address.RuleFor(x => x.Street).NotEmpty();
address.RuleFor(x => x.City).NotEmpty();
});
🏗️ Integration
ASP.NET Core
// Program.cs
builder.Services.AddScoped<IValidator<Customer>, CustomerValidator>();
// Controller
[ApiController]
public class CustomerController : ControllerBase
{
private readonly IValidator<Customer> _validator;
public CustomerController(IValidator<Customer> validator)
{
_validator = validator;
}
[HttpPost]
public async Task<IActionResult> CreateCustomer([FromBody] Customer customer)
{
var result = await _validator.ValidateAsync(customer);
if (!result.IsValid)
{
return BadRequest(result.Errors);
}
// Process valid customer
return Ok();
}
}
Blazor
@using FlexValidator
<EditForm Model="@customer" OnValidSubmit="@HandleValidSubmit">
<FlexValidatorValidator />
<ValidationSummary />
<InputText @bind-Value="customer.Name" />
<ValidationMessage For="@(() => customer.Name)" />
<button type="submit">Submit</button>
</EditForm>
@code {
private Customer customer = new();
private void HandleValidSubmit()
{
// Handle valid form submission
}
}
📚 Documentation
For comprehensive documentation, please visit our Wiki.
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for your changes
- Submit a pull request
📝 License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
🙏 Acknowledgments
- Inspired by FluentValidation
- Thanks to all contributors who have helped improve this library
📊 Performance
FlexValidator is designed for high-performance scenarios with:
- Compiled expressions for fast property access
- Minimal memory allocations
- Efficient async validation pipeline
🔗 Links
Made with ❤️ by Mohamed OUBAICH
Product | Versions 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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- System.Threading.Tasks.Extensions (>= 4.6.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.1 | 99 | 7/11/2025 |