Raycynix.Extensions.Contracts.AspNetCore 1.0.0

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

Raycynix.Extensions.Contracts.AspNetCore

Raycynix.Extensions.Contracts.AspNetCore adds ASP.NET Core integration for the shared contract types defined in Raycynix.Extensions.Contracts.

What it contains

  • endpoint metadata for declared contract identities
  • middleware for writing contract headers to HTTP responses
  • helpers for reading contract headers from incoming requests
  • minimal API helpers for contract-aware HTTP results
  • MVC helpers for converting ModelState into ErrorContract

Installation

builder.Services.AddRaycynixContractsAspNetCore();

var app = builder.Build();
app.UseRaycynixContracts();

Response Shape Options

Use plain contract results when you want headers plus the original response body:

app.MapGet("/catalog/prices/{id}", (HttpContext httpContext) =>
        httpContext.Contract(new Money
        {
            Amount = 149.99m,
            Currency = "USD"
        }))
    .WithContract("catalog.prices", "1.2.0");

Use VersionedContract(...) when you want the body wrapped into VersionedContract<T>.

How It Works

Contract support in ASP.NET Core has two separate parts:

  1. endpoint metadata, which declares the contract name and version for the HTTP endpoint
  2. response shaping, which decides whether the body is a plain DTO or a VersionedContract<T>

When you declare a contract on an endpoint, the middleware writes these response headers automatically:

  • X-Contract-Name
  • X-Contract-Version

Use the result helpers only when you also want the response body to follow a contract-aware shape.

Minimal API

Declare contract metadata directly on the endpoint:

app.MapGet("/catalog/prices", () =>
    httpContext => httpContext.VersionedContract(
        new[] { new Money { Amount = 149.99m, Currency = "USD" } }))
    .WithContract("catalog.prices", "1.2.0");

WithContract(...) declares the endpoint contract metadata.
httpContext.VersionedContract(...) reads that metadata from the current endpoint, wraps the response body into VersionedContract<T>, and writes the same contract headers.

If you only need headers and a plain response body, return a regular ASP.NET Core result:

app.MapGet("/catalog/prices/{id}", () =>
    TypedResults.Ok(new Money
    {
        Amount = 149.99m,
        Currency = "USD"
    }))
    .WithContract("catalog.prices", "1.2.0");

MVC / Controllers

For MVC controllers or actions, use the attribute:

[ApiController]
[Route("api/catalog/prices")]
[Contract("catalog.prices", "1.2.0")]
public sealed class CatalogController : ControllerBase
{
    [HttpGet("{id}")]
    public IResult GetPrice(string id)
    {
        var payload = new Money
        {
            Amount = 149.99m,
            Currency = "USD"
        };

        return this.VersionedContract(payload);
    }
}

The attribute declares endpoint metadata.
The middleware reads that metadata and writes the headers.
If you return this.VersionedContract(...), the body is wrapped into VersionedContract<T> using the same endpoint metadata.

If you return Ok(payload) or another normal controller result, the middleware still writes headers as long as the endpoint has [Contract(...)].

Declaring vs Writing

  • declare the contract on the endpoint:
    • Minimal API: .WithContract(...)
    • MVC: [Contract(...)]
  • write contract headers:
    • app.UseRaycynixContracts()
  • choose the response body format:
    • plain DTO/body: return Ok(...), TypedResults.Ok(...), etc.
    • versioned envelope: return this.VersionedContract(...) or httpContext.VersionedContract(...)

Request Header Access

Read incoming contract metadata from request headers:

if (httpContext.TryGetRequestContractMetadata(out var requestContract))
{
    // apply compatibility rules here
}

Validation Errors

Convert ASP.NET Core ModelState into the shared transport error shape:

var error = ModelState.ToErrorContract(traceId: HttpContext.TraceIdentifier);

This package intentionally provides transport integration only. It does not enforce compatibility policy or automatic contract negotiation.

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

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.0 33 4/8/2026
0.1.1 32 4/8/2026

See the repository changelog and release history for package-specific changes and breaking updates.