Muslim.Validator
10.0.1
dotnet add package Muslim.Validator --version 10.0.1
NuGet\Install-Package Muslim.Validator -Version 10.0.1
<PackageReference Include="Muslim.Validator" Version="10.0.1" />
<PackageVersion Include="Muslim.Validator" Version="10.0.1" />
<PackageReference Include="Muslim.Validator" />
paket add Muslim.Validator --version 10.0.1
#r "nuget: Muslim.Validator, 10.0.1"
#:package Muslim.Validator@10.0.1
#addin nuget:?package=Muslim.Validator&version=10.0.1
#tool nuget:?package=Muslim.Validator&version=10.0.1
Muslim.Validator
Run FluentValidation in one line and get back a simple list of errors, with messages in Arabic and English.
dotnet add package Muslim.Validator
Quick start
Write a validator. Each message can carry both languages:
using FluentValidation;
using Muslim.Validator;
public class CreateProductDto
{
public string Name { get; set; } = "";
public decimal Price { get; set; }
}
public class CreateProductValidator : AbstractValidator<CreateProductDto>
{
public CreateProductValidator()
{
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage(ValidatorErrorMessage.GetAsJson(new TranslateErrorMessage
{
Ar = "اسم المنتج مطلوب",
En = "Product name is required."
}));
RuleFor(x => x.Price)
.GreaterThan(0)
.WithMessage(ValidatorErrorMessage.GetAsJson(new TranslateErrorMessage
{
Ar = "السعر يجب أن يكون أكبر من صفر",
En = "Price must be greater than zero."
}));
}
}
Register your validators:
builder.Services.AddValidatorsFromAssemblyContaining<CreateProductValidator>();
Validate in an endpoint:
app.MapPost("/products", async (CreateProductDto dto, HttpContext http) =>
{
var (errors, isValid) = await ValidateResult.ErrorsAsync(dto, http.RequestServices, http.RequestAborted);
if (!isValid)
return Results.BadRequest(errors);
// save the product...
return Results.Ok();
});
An invalid request returns a body like this:
[
{
"propertyName": "Name",
"errorMessage": "{\"Ar\":\"اسم المنتج مطلوب\",\"En\":\"Product name is required.\"}"
}
]
The client parses errorMessage and shows Ar or En for the user's language.
Methods
| Method | When there is no validator for the DTO |
|---|---|
ErrorsAsync(dto, provider, ct) |
returns one error and IsValid = false |
Errors(dto, provider, out isValid) |
returns one error and isValid = false |
GetValidationResultAsync(dto, provider, ct) |
throws InvalidOperationException |
GetValidationResult(dto, provider, out isValid) |
throws InvalidOperationException |
- Use the async methods when a validator has
MustAsync,CustomAsyncorWhenAsync. They run both normal and async rules. - Pass the current request's provider (
HttpContext.RequestServices, or theIServiceProviderinjected into your service). Validators that use a scoped service such as aDbContextthen get the request's instance. - Every DTO you validate needs a validator. A missing one fails validation, so unchecked data never slips through. For a DTO with no rules, register an empty validator.
- If more than one validator is registered for the same DTO, the last one is used. Put the rules in
one validator and use
Includeto share them.
Without passing a provider
Each method also has an overload without the provider. Set the provider once at startup:
var app = builder.Build();
ValidateResult.SetServiceProvider(app.Services);
var errors = ValidateResult.Errors(dto, out var isValid);
var (asyncErrors, asyncIsValid) = await ValidateResult.ErrorsAsync(dto, cancellationToken);
This uses the root provider, so it is only safe for validators that do not depend on scoped services.
ValidateResult.ResetServiceProvider() clears it, for example between tests.
Good to know
TraslateErrorMessage, the older spelling, still works and produces the same JSON.- The missing-validator error has
PropertyName = "No Property To Validate "andErrorMessage = "No validators were found ". - Exceptions thrown inside your rules are not hidden. They reach your code like any other exception.
- This package uses FluentValidation 11.
Coding-agent guidance
When you build a project that uses this package, a short guide for AI coding agents is copied to
.agents/skills/muslim-validator/ at the root of your repository. Agents that read skills from
.agents/skills, such as Codex and GitHub Copilot in VS Code, use it to write correct code against
this package. Your own files and other skills are never touched, and nothing is deleted
automatically.
To turn it off, add this to your project or Directory.Build.props:
<PropertyGroup>
<MuslimValidatorGenerateSkill>false</MuslimValidatorGenerateSkill>
</PropertyGroup>
License
See LICENSE.txt.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- FluentValidation.DependencyInjectionExtensions (>= 11.12.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.13)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Muslim.Validator:
| Package | Downloads |
|---|---|
|
Muslim.Result
Typed operation results with validation errors, pagination, and synchronous and asynchronous composition. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Ships version-matched agent guidance and generates .agents/skills/muslim-validator during normal consuming builds. Preserves user files and supports MuslimValidatorGenerateSkill=false. See CHANGELOG.md.