StrongOf.AspNetCore 2.1.8

Requires NuGet 2.12 or higher.

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

StrongOf.AspNetCore

ASP.NET Core integration for StrongOf types. Includes MVC model binders, Minimal API validation, and OpenAPI schema transformation.

Installation

dotnet add package StrongOf.AspNetCore

MVC Model Binders (StrongOf.AspNetCore.Mvc)

Enables route values, query strings, and form fields to be automatically parsed into strong types.

Available Binders

Binder For
StrongGuidBinder<T> StrongGuid<T> types
StrongStringBinder<T> StrongString<T> types
StrongInt32Binder<T> StrongInt32<T> types
StrongInt64Binder<T> StrongInt64<T> types
StrongDecimalBinder<T> StrongDecimal<T> types
StrongDoubleBinder<T> StrongDouble<T> types
StrongCharBinder<T> StrongChar<T> types
StrongBooleanBinder<T> StrongBoolean<T> types
StrongDateTimeBinder<T> StrongDateTime<T> types
StrongDateTimeOffsetBinder<T> StrongDateTimeOffset<T> types
StrongTimeSpanBinder<T> StrongTimeSpan<T> types

Setup

Register a custom IModelBinderProvider in your ASP.NET Core startup:

using StrongOf.AspNetCore.Mvc;

// Program.cs
builder.Services.AddControllers(options =>
    options.ModelBinderProviders.Insert(0, new MyBinderProvider()));

// MyBinderProvider.cs
public sealed class MyBinderProvider : IModelBinderProvider
{
    private static readonly IReadOnlyDictionary<Type, Type> s_binders =
        new Dictionary<Type, Type>
        {
            { typeof(UserId),       typeof(StrongGuidBinder<UserId>)   },
            { typeof(EmailAddress), typeof(StrongStringBinder<EmailAddress>) },
        };

    public IModelBinder? GetBinder(ModelBinderProviderContext context)
    {
        if (s_binders.TryGetValue(context.Metadata.ModelType, out Type? binderType))
        {
            return new BinderTypeModelBinder(binderType);
        }
        return null;
    }
}

Custom Binders

Extend StrongOfBinder to add custom parsing logic:

using StrongOf.AspNetCore.Mvc;

public sealed class MyUserIdBinder : StrongOfBinder
{
    public override bool TryHandle(string value, out ModelBindingResult result)
    {
        if (StrongGuid<UserId>.TryParse(value, out UserId? id))
        {
            result = ModelBindingResult.Success(id);
            return true;
        }
        result = ModelBindingResult.Failed();
        return false;
    }
}

Minimal APIs (StrongOf.AspNetCore.MinimalApis)

All strong types implement IParsable<TSelf> and work as route/query parameters in Minimal APIs out of the box.

Use the validation filter to automatically validate IValidatable parameters:

using StrongOf.AspNetCore.MinimalApis;

// Strong types work as route parameters out of the box
app.MapGet("/users/{id}", (UserId id) => Results.Ok(id));

// Register the endpoint filter for automatic validation of IValidatable types
app.MapPost("/users", (EmailAddress email) => Results.Ok(email))
   .WithStrongOfValidation();

OpenAPI Schema Transformer (StrongOf.AspNetCore.OpenApi)

Requires .NET 9.0 or later

Maps strong types to their underlying primitive types in OpenAPI documentation, so API schemas show string (uuid) instead of a complex object for UserId.

using StrongOf.AspNetCore.OpenApi;

builder.Services.AddOpenApi(options =>
{
    options.AddSchemaTransformer<StrongOfSchemaTransformer>();
});

Type Mappings

Strong Type OpenAPI Type OpenAPI Format
StrongGuid<T> string uuid
StrongString<T> string -
StrongInt32<T> integer int32
StrongInt64<T> integer int64
StrongDecimal<T> number double
StrongChar<T> string -
StrongDateTime<T> string date-time
StrongDateTimeOffset<T> string date-time

GitHub

See https://github.com/BenjaminAbt/StrongOf

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.  net11.0 is compatible. 
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
2.1.8 85 2/28/2026
2.0.2 101 2/20/2026
1.2.15 642 4/26/2025
1.2.8 249 4/9/2025
1.2.7 1,950 2/18/2025
1.2.7-ga639164e54 137 2/18/2025
1.2.4 1,092 11/28/2024
1.2.4-g0988d2c02d 152 11/28/2024
1.2.2 804 11/15/2024
1.2.2-gbc3f3048e7 144 11/15/2024
1.1.4 199 11/12/2024
1.1.4-g6e854f6d6d 161 11/12/2024
1.1.2 284 11/5/2024
1.1.2-g0a1a51912f 137 11/5/2024
0.1.71 301 11/3/2024
0.1.71-g40ec49b665 160 11/3/2024
0.1.65 366 6/2/2024
0.1.65-g31f777a546 198 6/2/2024
0.1.63 213 6/1/2024
0.1.63-g3ca390c476 161 6/1/2024
Loading failed