Skip to content

Commit 22cdeb3

Browse files
authored
Merge pull request #56 from kolan72/main
Update dev-di from main.
2 parents 1f9f8b9 + 9cd8663 commit 22cdeb3

File tree

8 files changed

+323
-6
lines changed

8 files changed

+323
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.10.0
2+
3+
- Introduced the `QuickValidator.ValidateAsync<T>(T, Action<IRuleBuilderOptions<T, T>>, string, Action<T>, CancellationToken)` extension method.
4+
- Introduced the `QuickValidator.ValidateAsync<T>(T, Action<IRuleBuilderOptions<T, T>>, PropertyNameMode, Action<T>, CancellationToken)` extension method.
5+
- Edit 'Quick Validation' README Chapter.
6+
- Edit 'Quick Validation' NuGet README Chapter.
7+
8+
19
## 0.9.0
210

311
- Added quick validation support via `QuickValidator` and its `Validate<T>` overloads.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ExpressValidator is a library that provides the ability to validate objects usin
1818
- Supports adding a property or field for validation.
1919
- Verifies that a property expression is a property and a field expression is a field, and throws `ArgumentException` if it is not.
2020
- Supports adding a `Func` that provides a value for validation.
21-
- Provides quick validation (refers to ease of use).
21+
- Provides quick and easy validation using the `QuickValidator`.
2222
- Supports asynchronous validation.
2323
- Targets .NET Standard 2.0+
2424

@@ -159,6 +159,7 @@ var result = QuickValidator.Validate(
159159
.ChildRules((v) => v.RuleFor(o => o.PercentValue1).InclusiveBetween(0, 100)),
160160
nameof(obj));
161161
```
162+
The `QuickValidator` also provides a `ValidateAsync` method for asynchronous validation.
162163

163164
## 🧩 Nuances Of Using The Library
164165

src/ExpressValidator.Extensions.DependencyInjection/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.3.7
2+
3+
- Update ExpressValidator nuget package.
4+
- Split the DI extensions into a dedicated solution.
5+
- Update Microsoft nuget packages.
6+
- Update Microsoft NuGet packages for ExpressValidator.Extensions.DependencyInjection.Tests.
7+
8+
19
## 0.3.5
210

311
- Reduced unnecessary updates to validator parameters by listening to `IOptionsMonitor.Change` with named validation options.

src/ExpressValidator.Extensions.DependencyInjection/ExpressValidator.Extensions.DependencyInjection.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.3.5</Version>
6+
<Version>0.3.7</Version>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<Authors>Andrey Kolesnichenko</Authors>
99
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -15,7 +15,7 @@
1515
<PackageTags>FluentValidation Validation DependencyInjection</PackageTags>
1616
<Description>The ExpressValidator.Extensions.DependencyInjection package extends ExpressValidator to provide integration with Microsoft Dependency Injection.</Description>
1717
<Copyright>Copyright 2024 Andrey Kolesnichenko</Copyright>
18-
<AssemblyVersion>0.3.5.0</AssemblyVersion>
18+
<AssemblyVersion>0.3.7.0</AssemblyVersion>
1919
</PropertyGroup>
2020

2121
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/ExpressValidator/ExpressValidator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>0.9.0</Version>
6+
<Version>0.10.0</Version>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<Authors>Andrey Kolesnichenko</Authors>
99
<Description>ExpressValidator is a library that provides the ability to validate objects using the FluentValidation library, but without object inheritance from `AbstractValidator`.</Description>
@@ -15,7 +15,7 @@
1515
<PackageIcon>ExpressValidator.png</PackageIcon>
1616
<PackageReadmeFile>NuGet.md</PackageReadmeFile>
1717
<PackageIconUrl />
18-
<AssemblyVersion>0.9.0.0</AssemblyVersion>
18+
<AssemblyVersion>0.10.0.0</AssemblyVersion>
1919
<FileVersion>0.0.0.0</FileVersion>
2020
</PropertyGroup>
2121

src/ExpressValidator/QuickValidation/QuickValidator.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using FluentValidation;
33
using FluentValidation.Results;
44
using System;
5+
using System.Threading;
6+
using System.Threading.Tasks;
57

68
namespace ExpressValidator.QuickValidation
79
{
@@ -52,6 +54,48 @@ private static ValidationResult ValidateInner<T>(T obj, Action<IRuleBuilderOptio
5254
.BuildAndValidate(Unit.Default);
5355
}
5456

57+
/// <summary>
58+
/// Asynchronously validates the given object instance using <paramref name="action"/>.
59+
/// </summary>
60+
/// <typeparam name="T">The type of the object to validate.</typeparam>
61+
/// <param name="obj">The object to validate.</param>
62+
/// <param name="action">Action to add validators.</param>
63+
/// <param name="propName">The name of the property if the validation fails.
64+
/// If <see langword="null"/>, "Input" will be used.</param>
65+
/// <param name="onSuccessValidation">Specifies a method to execute when validation succeeds.</param>
66+
/// <param name="token">>A cancellation token to cancel validation.</param>
67+
/// <returns></returns>
68+
public static Task<ValidationResult> ValidateAsync<T>(T obj, Action<IRuleBuilderOptions<T, T>> action, string propName, Action<T> onSuccessValidation = null, CancellationToken token = default)
69+
{
70+
return ValidateInnerAsync(obj, action, propName ?? FALLBACK_PROP_NAME, onSuccessValidation, token);
71+
}
72+
73+
/// <summary>
74+
/// Asynchronously validates the given object instance using <paramref name="action"/>.
75+
/// </summary>
76+
/// <typeparam name="T">The type of the object to validate.</typeparam>
77+
/// <param name="obj">The object to validate.</param>
78+
/// <param name="action">Action to add validators.</param>
79+
/// <param name="mode"><see cref="PropertyNameMode"/>.
80+
/// If <see cref="PropertyNameMode.Default"/>, "Input" will be used.</param>
81+
/// <param name="onSuccessValidation">Specifies a method to execute when validation succeeds.</param>
82+
/// <param name="token">>A cancellation token to cancel validation.</param>
83+
/// <returns></returns>
84+
public static Task<ValidationResult> ValidateAsync<T>(T obj, Action<IRuleBuilderOptions<T, T>> action, PropertyNameMode mode = PropertyNameMode.Default, Action<T> onSuccessValidation = null, CancellationToken token = default)
85+
{
86+
return ValidateInnerAsync(obj, action, GetPropName<T>(mode), onSuccessValidation, token);
87+
}
88+
89+
private static Task<ValidationResult> ValidateInnerAsync<T>(T obj, Action<IRuleBuilderOptions<T, T>> action, string propName, Action<T> onSuccessValidation = null, CancellationToken token = default)
90+
{
91+
var eb = new ExpressValidatorBuilder<Unit>();
92+
return eb.AddFunc((_) => obj,
93+
propName,
94+
onSuccessValidation)
95+
.WithAsyncValidation(action)
96+
.BuildAndValidateAsync(Unit.Default, token);
97+
}
98+
5599
private static string GetPropName<T>(PropertyNameMode mode) => mode == PropertyNameMode.Default ? FALLBACK_PROP_NAME : typeof(T).Name;
56100
}
57101
}

src/ExpressValidator/docs/NuGet.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ExpressValidator is a library that provides the ability to validate objects usin
88
- Supports adding a property or field for validation.
99
- Verifies that a property expression is a property and a field expression is a field, and throws `ArgumentException` if it is not.
1010
- Supports adding a `Func` that provides a value for validation.
11-
- Provides quick validation (refers to ease of use).
11+
- Provides quick and easy validation using the `QuickValidator`.
1212
- Supports asynchronous validation.
1313
- Targets .NET Standard 2.0+
1414

@@ -144,6 +144,7 @@ var result = QuickValidator.Validate(
144144
.ChildRules((v) => v.RuleFor(o => o.PercentValue1).InclusiveBetween(0, 100)),
145145
nameof(obj));
146146
```
147+
The `QuickValidator` also provides a `ValidateAsync` method for asynchronous validation.
147148

148149
## Nuances Of Using The Library
149150

0 commit comments

Comments
 (0)