Midas.Validation 1.0.6

dotnet add package Midas.Validation --version 1.0.6
                    
NuGet\Install-Package Midas.Validation -Version 1.0.6
                    
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="Midas.Validation" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Midas.Validation" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Midas.Validation" />
                    
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 Midas.Validation --version 1.0.6
                    
#r "nuget: Midas.Validation, 1.0.6"
                    
#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 Midas.Validation@1.0.6
                    
#: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=Midas.Validation&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Midas.Validation&version=1.0.6
                    
Install as a Cake Tool

Midas.Validation

NuGet NuGet Downloads License: MIT Support Us Sponsor

FluentValidation base classes and extensions for .NET healthcare applications.
Built by Midas Path Software Solutions for clean-architecture HMS systems.


Installation

dotnet add package Midas.Validation

Quick Start

1. Create a validator

using FluentValidation;
using Midas.Validation;

public class RegisterPatientCommandValidator : MidasValidator<RegisterPatientCommand>
{
    public RegisterPatientCommandValidator()
    {
        RuleFor(x => x.FullName)
            .NotEmpty()
            .MaximumLength(200);

        // Built-in domain rules
        GhanaPhone(RuleFor(x => x.PhoneNumber));
        NhisId(RuleFor(x => x.NhisId));
        EmailAddress(RuleFor(x => x.Email));
        NotFutureDate(RuleFor(x => x.DateOfBirth));
    }
}

2. Register in Program.cs (once)

builder.Services.AddMidasValidators(
    typeof(RegisterPatientCommandValidator).Assembly
);

3. Use in a MediatR pipeline behaviour

public class ValidationBehaviour<TRequest, TResponse>(
    IEnumerable<IValidator<TRequest>> validators)
    : IPipelineBehavior<TRequest, TResponse>
{
    public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken ct)
    {
        var context = new ValidationContext<TRequest>(request);
        var results = await Task.WhenAll(validators.Select(v => v.ValidateAsync(context, ct)));
        var failures = results.SelectMany(r => r.Errors).Where(f => f is not null).ToList();

        if (failures.Count > 0)
            throw new MidasValidationException(failures);

        return await next();
    }
}

4. Map to RFC 7807 Problem Details in the API layer

app.UseExceptionHandler(builder => builder.Run(async context =>
{
    var ex = context.Features.Get<IExceptionHandlerFeature>()?.Error;
    if (ex is MidasValidationException ve)
    {
        context.Response.StatusCode = 422;
        await context.Response.WriteAsJsonAsync(new ValidationProblemDetails(ve.ToDictionary()));
    }
}));

Built-in Domain Rules

Helper Validates
GhanaPhone(rule) 10-digit Ghanaian phone number starting with 0
NhisId(rule) NHIS membership ID (6–15 alphanumeric chars)
EmailAddress(rule) Standard email format
NotFutureDate(rule) DateTime / DateTime? not in the future

All helpers return IRuleBuilderOptions<T, TProp> so you can chain additional FluentValidation rules.


API Reference

MidasValidator<T>

Abstract base class extending AbstractValidator<T>. Provides the domain rule helpers above.

MidasValidationException

Thrown when validation fails. Carries IReadOnlyList<ValidationFailure> Errors.
ToDictionary() returns IDictionary<string, string[]> for ValidationProblemDetails.

ValidationExtensions

  • result.ToDictionary() — converts a ValidationResult to a field→messages dictionary
  • result.ThrowIfInvalid() — throws MidasValidationException if result is invalid

AddMidasValidators(params Assembly[])

Scans assemblies for IValidator<T> implementations and registers them as scoped services.


Target Frameworks

  • net9.0

License

MIT © Midas Path Software Solutions

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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.  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

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.0.6 26 4/5/2026
1.0.5 39 4/4/2026
1.0.4 89 3/14/2026
1.0.3 88 3/9/2026