Repository navigation
ASP.NET Core
github-actions[bot] edited this page Nov 29, 2026
·
1 revision
Celly.Json.AspNetCore integrates Celly.Json into ASP.NET Core with zero third-party dependencies beyond Celly.Json and Microsoft.AspNetCore.App (fully NativeAOT and trimming compatible).
dotnet add package Celly.Json.AspNetCoreRegister CelEnv, CelJsonOptions, ICelProgramCache, and CelAuthorizationHandler in Program.cs:
builder.Services.AddCellyJson(options =>
{
options.MaxCachedPrograms = 1024;
options.MaxJsonBodyBytes = 1024 * 1024; // 1 MiB cap when buffering JSON bodies
});Expressions evaluated in authorization policies and endpoint filters receive a lazy HttpContextActivation with three root variables:
| Root Variable | Fields / Indexing |
|---|---|
request |
method, path, scheme, host, contentType, headers['X-Tenant'], query['page'], route['id']
|
user |
authenticated, name, authenticationType, roles (supports 'admin' in user.roles), claims['dept']
|
body |
Lazily adapted JSON request body (when parseJsonBody: true; automatically buffered and rewound so downstream handlers can still read it) |
builder.Services.AddAuthorizationBuilder()
.AddCelPolicy(
"CanRefund",
"user.authenticated && ('admin' in user.roles || (body.amount < 100 && user.claims['dept'] == 'support'))",
parseJsonBody: true);
app.MapPost("/refunds", HandleRefund).RequireAuthorization("CanRefund");Guard any endpoint or route group with a boolean CEL expression:
app.MapPost("/orders", CreateOrder)
.RequireCel(
"body.total > 0 && body.items.all(i, i.qty > 0)",
failureStatusCode: StatusCodes.Status400BadRequest,
failureMessage: "Order total and item quantities must be positive.");Stream any CelValue directly to HttpResponse.BodyWriter via Utf8JsonWriter without allocating intermediate strings or byte arrays:
app.MapPost("/eval", (CelProgram program, JsonDocument payload) =>
{
var result = program.EvalJson(payload);
return Results.Extensions.CelJson(result);
});Celly.Json — High-performance System.Text.Json adapter for Celly (.NET 10, NativeAOT-ready, MIT License).