Muslim.Validator 10.0.1

dotnet add package Muslim.Validator --version 10.0.1
                    
NuGet\Install-Package Muslim.Validator -Version 10.0.1
                    
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="Muslim.Validator" Version="10.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muslim.Validator" Version="10.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Muslim.Validator" />
                    
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 Muslim.Validator --version 10.0.1
                    
#r "nuget: Muslim.Validator, 10.0.1"
                    
#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.
#:package Muslim.Validator@10.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Muslim.Validator&version=10.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Muslim.Validator&version=10.0.1
                    
Install as a Cake Tool

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, CustomAsync or WhenAsync. They run both normal and async rules.
  • Pass the current request's provider (HttpContext.RequestServices, or the IServiceProvider injected into your service). Validators that use a scoped service such as a DbContext then 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 Include to 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 " and ErrorMessage = "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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
10.0.1 164 10/15/2026
8.0.0 185 9/23/2026
1.0.0 378 10/5/2024

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.