FlowValidate 1.0.8
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FlowValidate --version 1.0.8
NuGet\Install-Package FlowValidate -Version 1.0.8
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="FlowValidate" Version="1.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlowValidate" Version="1.0.8" />
<PackageReference Include="FlowValidate" />
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 FlowValidate --version 1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FlowValidate, 1.0.8"
#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.
#addin nuget:?package=FlowValidate&version=1.0.8
#tool nuget:?package=FlowValidate&version=1.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FlowValidate
FlowValidate is a lightweight, fluent validation library for validating request-based models in .NET 8.0.
It offers an intuitive API for model validation, making it easy to enforce rules for your application�s request models. FlowValidate simplifies the process of adding validation logic to your models with an easy-to-use interface, reducing boilerplate code.
Features
- Property Validation: Validate standard properties, nested classes, and collections.
- Custom Validation Methods: Includes pre-built methods like
Should
,Must
,IsNotEmpty
, andIsEqual
. These methods make property validation easier and allow you to create custom validation logic. - Dependency Injection (DI) Support: Easily integrate with your application's DI system.
- Detailed Error Messages: Provides detailed validation error messages for easy debugging.
- Lightweight & Fast: Designed for high performance, optimized for .NET 8.0.
- Middleware Support: FlowValidate can be used as middleware to validate models automatically on each request, reducing boilerplate code.
Installation
You can install FlowValidate via NuGet Package Manager
Injection
var builder = WebApplication.CreateBuilder(args);
builder.Services.FlowVal(AssemblyReference.Assembly);
var app = builder.Build();
app.FlowValApp();
app.Run();
For example, we create a uservalidator
public class UserValidator : BaseValidator<User>
{
public UserValidator()
{
RuleFor(user => user.Name)
.Must(name => !string.IsNullOrEmpty(name)).WithMessage("Name property is null !")
.Contains("e").WithMessage("Name property value have to contains 'e' .")
.Length(3, 10).WithMessage("Length doesn't follow the rules")
.IsEqual("XoarkanX").WithMessage("Name value is not equal qith expected value !")
.IsEmail().WithMessage("Name is not email")
.Should(name =>
{
if (!name.Contains("e"))
throw new Exception("Name cannot start with 'X'.");
}, "Custom validation FAILED !").WithMessage("Additional error message if needed.")
.Should(name => char.IsUpper(name[0]), "Name must start with an uppercase letter");
ValidateNested(user => user.UserCustomer, new UserCustomersValidator());
RuleFor(user => user.Age)
.Length(1, 2).WithMessage("Age range can't be bigger than three step")
.IsEqual(17).WithMessage("yas 17 olmali");
ValidateCollection(
ubas => ubas.UserBaskets,
new UserBasketsValidator(),
item => item
);
RuleFor(user => user.Age)
.Should(age =>
{
throw new Exception();
}, "example error");
RuleFor(user => user)
.Must(user =>
{
if (!user.Name.Contains("y"))
return false;
return true;
}).WithMessage("user name must be contains 'y' character !")
.Must(user =>
{
if (user.Name.Length < 5)
return false;
return true;
}).WithMessage("user name length at least be than 3");
}
}
we can verify as manuel
var user = new User
{
Name = "XoarkanX",
Age = 18,
UserCustomer = new()
{
Email = "",
PhoneNumber = "1234f56789"
},
UserBaskets = new()
{
new UserBasket(){Count = 0,Name = ""},
new UserBasket(){Count = 52,Name = ""}
}
};
var validator = new UserValidator();
var result = validator.Validate(user);
output
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.AspNetCore.Http (>= 2.1.34)
- Microsoft.AspNetCore.Mvc.ApiExplorer (>= 2.1.0)
- Microsoft.AspNetCore.Routing (>= 2.1.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.