FlowValidate 1.1.2

dotnet add package FlowValidate --version 1.1.2
                    
NuGet\Install-Package FlowValidate -Version 1.1.2
                    
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.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FlowValidate" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="FlowValidate" />
                    
Project file
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.1.2
                    
#r "nuget: FlowValidate, 1.1.2"
                    
#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.1.2
                    
Install as a Cake Addin
#tool nuget:?package=FlowValidate&version=1.1.2
                    
Install as a Cake Tool
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: Provides validation of standard properties, nested classes and collections.
  • Nested Class & Collection Support: Nested automatically traverses and validates complex types and collections, eliminating repetitive validation code.
  • Custom Validation Methods: It simplifies property validation with ready-made methods such as Should, Must, IsNotEmpty, IsEqual and allows you to write custom validation logic.
  • Reusable Validation Logic: Allows you to define custom validation rules once and reuse them across multiple properties or types.
  • Dependency Injection (DI) Support: Provides easy integration with the application's DI system.
  • Detailed Error Messages: Provides detailed validation error messages that make debugging easy.
  • Lightweight & Fast: Designed for high performance and optimized for .NET 8.0.
  • Middleware Support: FlowValidate can be used as middleware, automatically validating models on every request and reducing boilerplate code.
Installation

You can install FlowValidate via NuGet Package Manager

Injection
var builder = WebApplication.CreateBuilder(args);

builder.Services.FlowValidationService(AssemblyReference.Assembly); 

var app = builder.Build();

app.FlowValidationApp();

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 define specify validators for
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);
we can define specify validators for repeated use
    public class UserNameValidator : BaseValidator<string>
    {
        public UserNameValidator()
        {
            _rules.Add(name =>
            {
                var result = new ValidationResult();

                if (string.IsNullOrWhiteSpace(name))
                    result.Errors.Add("*** Username cannot be empty ***.");
                else
                {
                    if (name.Length < 3 || name.Length > 20)
                        result.Errors.Add("*** Username must be between 3 and 20 characters. ***.");
                    if (name.Contains(" "))
                        result.Errors.Add("*** Username cannot contain spaces ***.");
                    if (!System.Text.RegularExpressions.Regex.IsMatch(name, @"^[a-zA-Z0-9_]+$"))
                        result.Errors.Add("*** Username can only contain letters, numbers and underscores ***.");
                    if (!char.IsLetterOrDigit(name[0]))
                        result.Errors.Add("*** Username must start with a letter or number ***.");
                }
                result.SetIsValid(result.Errors.Count == 0);
                return result;
            });

        }
    }

    public class UserValidator : BaseValidator<User>
    {
        public UserValidator()
        {
            ValidateRegistryRules(u => u.Name, new UserNameValidator());
        }
    }
Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 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.

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.1.2 151 5/18/2025
1.1.1 139 5/18/2025
1.1.0 153 4/24/2025
1.0.9 152 3/19/2025
1.0.8 149 3/19/2025
1.0.7 163 3/10/2025
1.0.6 157 3/10/2025