Skip to main content
Opinionated service defaults for ASP.NET Core applications, inspired by .NET Aspire. The Web SDK (ANcpLua.NET.Sdk.Web) automatically configures these when you use WebApplication.CreateBuilder().

Features

FeatureDescription
OpenTelemetryLogging, metrics (ASP.NET Core, HTTP, Runtime), tracing with OTLP export
Health Checks/health (readiness) and /alive (liveness) endpoints
Service DiscoveryMicrosoft.Extensions.ServiceDiscovery enabled
HTTP ResilienceStandard resilience handlers with retries and circuit breakers
JSON ConfigurationCamelCase naming, enum converters, nullable annotations
SecurityForwarded headers, HTTPS redirect, HSTS, antiforgery
Static AssetsStatic file serving with proper caching
OpenAPIOptional OpenAPI/Swagger documentation
DevLogsFrontend console log bridge for unified debugging (Development only)

Usage

var builder = WebApplication.CreateBuilder(args);
builder.UseANcpSdkConventions();

var app = builder.Build();
app.MapANcpSdkDefaultEndpoints();
app.Run();
When using ANcpLua.NET.Sdk.Web, the source generator automatically intercepts WebApplication.CreateBuilder() calls, so explicit registration is optional.

Configuration

Customize behavior through the options callback:
builder.UseANcpSdkConventions(options =>
{
    options.Https.Enabled = true;
    options.OpenApi.Enabled = true;
    options.AntiForgery.Enabled = false;
    options.DevLogs.Enabled = true;
    options.OpenTelemetry.ConfigureTracing = tracing => tracing.AddSource("MyApp");
});

Configuration Options

Https

HTTPS and HSTS settings
PropertyTypeDefaultDescription
EnabledbooltrueEnable/disable this feature
HstsEnabledbooltrueEnable HTTP Strict Transport Security

OpenApi

OpenAPI/Swagger settings
PropertyTypeDefaultDescription
EnabledbooltrueEnable/disable this feature
ConfigureOpenApiAction<OpenApiOptions>?nullCustom OpenAPI options callback

OpenTelemetry

Telemetry configuration
PropertyTypeDefaultDescription
ConfigureLoggingAction<OpenTelemetryLoggerOptions>?nullCustom logging configuration callback
ConfigureMetricsAction<MeterProviderBuilder>?nullCustom metrics configuration callback
ConfigureTracingAction<TracerProviderBuilder>?nullCustom tracing configuration callback

AntiForgery

Anti-forgery token settings
PropertyTypeDefaultDescription
EnabledbooltrueEnable/disable this feature

StaticAssets

Static file serving
PropertyTypeDefaultDescription
EnabledbooltrueEnable/disable this feature

DevLogs

Browser console bridge
PropertyTypeDefaultDescription
EnabledbooltrueEnable/disable this feature
RoutePatternstring"/api/dev-logs"URL route pattern for the endpoint
EnableInProductionbool-Allow in production (security risk)

DevLogs - Frontend Console Bridge

Captures browser console.log/warn/error and sends to server logs. Enabled by default in Development. Add to your HTML (only served in Development):
<script src="/dev-logs.js"></script>
All frontend logs appear in server output with [BROWSER] prefix:
info: DevLogEntry[0] [BROWSER] User clicked button
warn: DevLogEntry[0] [BROWSER] Deprecated API called
error: DevLogEntry[0] [BROWSER] Failed to fetch data

Opt-out

To disable auto-registration and configure services manually:
<PropertyGroup>
  <AutoRegisterServiceDefaults>false</AutoRegisterServiceDefaults>
</PropertyGroup>