Dosaic.Plugins.Validations.AttributeValidation 1.0.35

There is a newer version of this package available.
See the version list below for details.
dotnet add package Dosaic.Plugins.Validations.AttributeValidation --version 1.0.35
                    
NuGet\Install-Package Dosaic.Plugins.Validations.AttributeValidation -Version 1.0.35
                    
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="Dosaic.Plugins.Validations.AttributeValidation" Version="1.0.35" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dosaic.Plugins.Validations.AttributeValidation" Version="1.0.35" />
                    
Directory.Packages.props
<PackageReference Include="Dosaic.Plugins.Validations.AttributeValidation" />
                    
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 Dosaic.Plugins.Validations.AttributeValidation --version 1.0.35
                    
#r "nuget: Dosaic.Plugins.Validations.AttributeValidation, 1.0.35"
                    
#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=Dosaic.Plugins.Validations.AttributeValidation&version=1.0.35
                    
Install Dosaic.Plugins.Validations.AttributeValidation as a Cake Addin
#tool nuget:?package=Dosaic.Plugins.Validations.AttributeValidation&version=1.0.35
                    
Install Dosaic.Plugins.Validations.AttributeValidation as a Cake Tool

Dosaic.Plugins.Validations.AttributeValidation

Dosaic.Plugins.Validations.AttributeValidation is a plugin that allows other Dosaic components to validate object using attributes.

Installation

To install the nuget package follow these steps:

dotnet add package Dosaic.Plugins.Validations.AttributeValidation

or add as package reference to your .csproj

<PackageReference Include="Dosaic.Plugins.Validations.AttributeValidation" Version="" />

Appsettings.yml

You do not need to configure anything, because the implementation resolver, does this automatically at startup.

Usage

The validator is auto-registered using the Plugin technology. You can use it by adding the Validations attribute to your model and inject the IValidator in your usage.

However, there are following Validations attibutes:

  • Required
  • Expression
  • Array
    • Length
    • MinLength
    • MaxLength
  • Bool
    • True
    • False
  • Date
    • Before
    • After
    • Age
    • MinAge
    • MaxAge
  • Int
    • Range
    • Min
    • Max
    • Positive
    • Negative
  • String
    • Length
    • MinLength
    • MaxLength
    • Email
    • Url
    • Regex

Example:
```csharp
internal class DbModel {
    [Validations.Required]
    public string Id {get;set;}
    [Validations.String.MinLength(5), Validations.String.MaxLength(10), Validations.String.Regex(@"^[a-zA-Z]+$")]
    public string LongName {get;set;}
    [Validations.Expression("Value % 2 == 0")]
    public int SomeNumber {get;set;}
}

// USAGE:
IServiceProvider sp;
var validator = sp.GetRequiredService<IValidator>();
var dbModel = new DbModel { Id = "1", LongName = "LongName", SomeNumber = 2 };
var result = await validator.ValidateAsync(dbModel);
Console.WriteLine(result.IsValid); // true
var failModel = new DbModel { Id = "", LongName = "..", SomeNumber = 3 };
var result = await validator.ValidateAsync(dbModel);
Console.WriteLine(result.IsValid); // false
Console.WriteLine(result.Errors); // List of errors
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.

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.1 31 5/6/2025
1.1.0 69 5/2/2025
1.0.37 159 4/7/2025
1.0.36 466 3/25/2025
1.0.35 218 3/4/2025
1.0.34 207 3/4/2025
1.0.32 139 3/3/2025
1.0.30 106 1/30/2025
1.0.27 106 1/29/2025
1.0.26 91 1/29/2025
1.0.25 86 1/29/2025