StrongOf.FluentValidation
StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.
Install
| Product | Versions |
|---|---|
| .NET |
README
StrongOf.FluentValidation
FluentValidation extensions for StrongOf types.
NativeAOT boundary
This extension does not promise NativeAOT compatibility for its FluentValidation dependency. Its source is
checked with the AOT and trimming analyzers, but the assembly is not marked IsAotCompatible and the
repository's native smoke test does not cover FluentValidation.
For validation without that dependency, use IValidatable, StrongValidation.TryCreate or
StrongValidation.Require from the AOT-compatible core package. Applications using FluentValidation must
publish and test their complete validator configuration and dependencies separately.
Why Not NotNull()?
For strong types, NotNull() only checks the object reference. StrongOf provides HasValue() which covers both nullability and empty values:
public sealed class UserValidator : AbstractValidator<User>
{
public UserValidator()
{
RuleFor(x => x.UserId)
.HasValue() // not NotNull()
.WithMessage("User ID is required.");
RuleFor(x => x.Email)
.HasValue()
.WithMessage("Email is required.");
}
}
Available Extensions
Common (all strong types)
| Method | Applies To | Description |
|---|---|---|
HasValue() |
All strong types | Not null and, for string types, not empty/whitespace |
IsEqualTo(Func<T,TStrong?>, string) |
Type-specific validators that support comparisons | Must equal another property; pass accessor and member name |
IsNotEqualTo(Func<T,TStrong?>, string) |
Type-specific validators that support comparisons | Must not equal another property; pass accessor and member name |
StrongString
| Method | Description |
|---|---|
HasMinimumLength(int) |
Minimum character length |
HasMaximumLength(int) |
Maximum character length |
IsRegexMatch(Regex) |
Must match a regular expression |
AllowedChars(ICollection<char>, string) |
Must only contain characters from the allowed set |
StrongInt32 / StrongInt64
| Method | Description |
|---|---|
HasMinimum(int/long) |
Value must be ≥ min |
HasMaximum(int/long) |
Value must be ≤ max |
HasRange(int/long, int/long) |
Value must be within [min, max] |
StrongDateTime / StrongDateTimeOffset
| Method | Description |
|---|---|
HasMinimum(DateTime/DateTimeOffset) |
Value must be ≥ min |
HasMaximum(DateTime/DateTimeOffset) |
Value must be ≤ max |
HasRange(DateTime/DateTimeOffset, ...) |
Value must be within [min, max] |
Installation
dotnet add package StrongOf.FluentValidation
GitHub
Changes from Previous Version
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.