Recipe

Recipe: ASP.NET controller scaffold

Drop-in controller base class that validates a Meridian license key on every request. Works with .NET 6+ minimal APIs and traditional controllers.

NuGet install

dotnet add package Meridian.AspNet --version 2.1.0

Controller base

[ApiController]
[Route("api/v1")]
public class LicensedController : ControllerBase
{
    private readonly LicenseValidator _validator;

    public LicensedController(LicenseValidator validator)
    {
        _validator = validator;
    }

    protected async Task<IActionResult> RequireLicense(
        string key, string hwid)
    {
        var result = await _validator.ValidateAsync(key, hwid);
        if (!result.IsValid)
            return Unauthorized(new { error = result.Reason });
        return Ok();
    }
}

appsettings.json

{
  "Meridian": {
    "ApiBase": "https://api.getnimbus.net",
    "CacheMinutes": 5,
    "EnforceHwid": true
  }
}

Program.cs wiring

builder.Services.AddMeridian(
    builder.Configuration.GetSection("Meridian"));

Next: Recipe: Go middleware — same pattern for net/http and Gin.