Skip to content

ASP.NET Core

SuperStrong.Types works with ASP.NET Core out of the box, in both minimal APIs and MVC controllers. No package or setup is required.

Route and query parameters

You can use strong types as route and query parameters directly. Minimal APIs bind them through the generated TryParse(...), controllers through the generated TypeConverter:

csharp
app.MapGet("/orders/{id}", (OrderId id) =>
{
    // todo: get order
});
csharp
[HttpGet("orders/{id}")]
public Order GetOrder(OrderId id)
{
    // todo: get order
}

Query parameters bind the same way.

Request body

JSON request bodies are handled by the System.Text.Json integration, so strong types can appear anywhere in a request DTO:

csharp
public sealed record CreateOrderRequest(UserId CustomerId, Username CreatedBy);
csharp
app.MapPost("/orders", (CreateOrderRequest request) =>
{
    // todo: create order
});
csharp
[HttpPost("orders")]
public Order CreateOrder([FromBody] CreateOrderRequest request)
{
    // todo: create order
}

Responses work in reverse: strong types are serialized as their underlying primitives.

Invalid values

A value that fails parsing or validation never reaches your handler. ASP.NET Core responds with 400 Bad Request instead, no matter where the value comes from: a route, a query string, or a request body.

OpenAPI

To map strong types correctly in a generated OpenAPI document, use the OpenAPI integration.

Released under the MIT License.