Masterly.NonEmptyList.AspNetCore 3.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Masterly.NonEmptyList.AspNetCore --version 3.0.0
                    
NuGet\Install-Package Masterly.NonEmptyList.AspNetCore -Version 3.0.0
                    
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="Masterly.NonEmptyList.AspNetCore" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Masterly.NonEmptyList.AspNetCore" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Masterly.NonEmptyList.AspNetCore" />
                    
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 Masterly.NonEmptyList.AspNetCore --version 3.0.0
                    
#r "nuget: Masterly.NonEmptyList.AspNetCore, 3.0.0"
                    
#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 Masterly.NonEmptyList.AspNetCore@3.0.0
                    
#: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=Masterly.NonEmptyList.AspNetCore&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Masterly.NonEmptyList.AspNetCore&version=3.0.0
                    
Install as a Cake Tool

Masterly.NonEmptyList.AspNetCore

ASP.NET Core integration for Masterly.NonEmptyList: the non-empty guarantee shows up in your OpenAPI document, and Validation<T, ValidationError> turns into RFC 7807 problem details in one call.

Installation

dotnet add package Masterly.NonEmptyList.AspNetCore

Binding works without this package

NonEmptyList<T>, NonEmptySet<T> and NonEmptyString have a static TryParse, and NonEmptyList<T> and NonEmptyString also ship a TypeConverter, so minimal APIs and MVC bind them from query strings and route values out of the box. An empty value is a 400 before your handler runs, and an empty JSON array in a request body is a 400 as well.

app.MapGet("/products", (NonEmptyList<int> ids) => repo.GetByIds(ids));   // ?ids=1,2,3
app.MapGet("/hello/{name}", (NonEmptyString name) => $"Hello {name}");

OpenAPI (.NET 9 and later)

builder.Services.AddOpenApi(options => options.AddNonEmptySchemas());
Type Schema
NonEmptyList<T>, ImmutableNonEmptyList<T> type: array, minItems: 1, plus items: T on .NET 10
NonEmptySet<T> minItems: 1, uniqueItems: true
ConstrainedList<T, AtLeast<Two>> and friends minItems / maxItems / uniqueItems derived from the constraint
NonEmptyDictionary<TKey, TValue> type: object, minProperties: 1, plus additionalProperties on .NET 10
NonEmptyString type: string, minLength: 1
[NonEmptyCollection] classes bounds from MinCount, MaxCount, IsDistinct

Validation to HTTP

app.MapPost("/orders", (CreateOrder request) =>
    Validation.Combine(
        Validation.NotBlank(request.Customer, new ValidationError("required", "Customer is required", "customer")),
        Validation.Ensure(request.Lines, l => l.All(x => x.Length > 0), new ValidationError("blank", "Lines cannot be blank", "lines")),
        (customer, lines) => new Order(customer, lines))
    .ToResult());                                   // 200 with the order, or 400 problem details
{
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": { "customer": ["Customer is required"], "lines": ["Lines cannot be blank"] },
  "codes": ["required", "blank"]
}

Also available: ToResult(onValid), ToCreatedResult(location), ToResultAsync, ToValidationProblem(), ToProblemDetails(), and for MVC ToActionResult(), ModelState.AddErrors(errors) and validation.TryGetValue(ModelState, out value).

NonEmptyShape.Of(type) exposes the cardinality a type guarantees (minimum, maximum, uniqueness) for your own tooling.

Documentation

Full guide: ASP.NET Core.

License

MIT

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
3.0.1 96 11/2/2026
3.0.0 92 11/2/2026

v3.0.0:
- Initial release: AddNonEmptySchemas() OpenAPI transformer (.NET 9+), Validation.ToResult / ToValidationProblem, ModelState.AddErrors