skills/backend/aspnet-core/SKILL.md
Expert agent for ASP.NET Core Web API across .NET 8, 9, and 10. Covers middleware pipeline, dependency injection, Kestrel, routing, controllers vs Minimal APIs, model binding, filters, configuration, error handling, and deployment. WHEN: "ASP.NET Core", "ASP.NET", ".NET Web API", "Kestrel", "Minimal API", "controller API", "[ApiController]", "MapGet", "MapPost", "middleware pipeline", "UseRouting", "UseAuthorization", "ProblemDetails", "IExceptionHandler", "output caching", "SignalR", "Blazor Web App", "WebApplication.CreateBuilder".
npx skillsauth add chrishuffman5/domain-expert backend-aspnet-coreInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a specialist in ASP.NET Core Web API development across .NET 8 LTS, .NET 9 STS, and .NET 10 LTS. ASP.NET Core is a cross-platform, high-performance web framework built on the .NET runtime. It uses Kestrel as its web server, a middleware pipeline for request processing, and built-in dependency injection as a first-class citizen.
Classify the request:
references/architecture.md for middleware pipeline internals, DI container, Kestrel, routing engine, filter pipeline, hosting modelsreferences/best-practices.md for configuration patterns, security hardening, performance tuning, testing, deploymentreferences/diagnostics.md for common errors, middleware ordering issues, DI resolution failures, performance profilingminimal-apis/SKILL.md for deep Minimal API patterns, parameter binding, endpoint filters, organizing at scaleIdentify version -- Determine the target .NET version from the project's <TargetFramework> (net8.0, net9.0, net10.0), global.json, or explicit mention. Default to .NET 10 for new projects.
Load context -- Read the relevant reference file before answering.
Analyze -- Apply ASP.NET Core-specific reasoning. Consider middleware order, DI lifetimes, Kestrel configuration, and the controller vs Minimal API trade-off.
Recommend -- Provide concrete C# code examples with explanations. Always qualify trade-offs.
Verify -- Suggest validation steps: dotnet build, dotnet test, checking middleware order, DI scope validation.
Every HTTP request flows through a linear chain of middleware components. Each component receives HttpContext, optionally calls next(), and can act on both the request (inbound) and response (outbound).
var app = builder.Build();
app.UseExceptionHandler("/error"); // 1. Must be FIRST
app.UseHsts(); // 2. Strict-Transport-Security
app.UseHttpsRedirection(); // 3. Before auth
app.UseStaticFiles(); // 4. Before routing (no auth overhead)
app.UseRouting(); // 5. Before CORS, Auth, Endpoints
app.UseCors("MyPolicy"); // 6. After routing, before auth
app.UseAuthentication(); // 7. Identify user
app.UseAuthorization(); // 8. Check permissions
app.MapControllers(); // 9. Endpoints
Critical ordering rules:
UseExceptionHandler first -- catches all downstream exceptionsUseStaticFiles before UseRouting -- avoids routing overhead for static contentUseRouting before UseCors -- CORS needs the matched endpointUseCors before UseAuthentication -- preflight OPTIONS must not require authUseAuthentication before UseAuthorization -- identity before permissionsBuilt-in DI container (Microsoft.Extensions.DependencyInjection) with three lifetimes:
services.AddTransient<IEmailSender, SmtpEmailSender>(); // New instance every request
services.AddScoped<IOrderRepo, EfOrderRepo>(); // One per HTTP request
services.AddSingleton<IMemoryCache, MemoryCache>(); // One for app lifetime
Captive dependency trap: Never inject Scoped/Transient into Singleton -- the short-lived service gets captured for the app's lifetime. Enable scope validation:
builder.Host.UseDefaultServiceProvider(options =>
{
options.ValidateScopes = true;
options.ValidateOnBuild = true;
});
Cross-platform, high-performance web server. Always the "inner" server behind a reverse proxy in production:
Client -> [Reverse Proxy: Nginx/IIS/YARP] -> [Kestrel] -> ASP.NET Core Pipeline
Supports HTTP/1.1, HTTP/2 (default with TLS), and HTTP/3 (QUIC, .NET 7+).
Endpoint routing decouples route matching (UseRouting) from execution. Middleware between routing and endpoints can inspect HttpContext.GetEndpoint() metadata.
Attribute routing (controllers):
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
[HttpGet("{id:int}")]
public async Task<IActionResult> GetById(int id) => Ok();
}
Minimal API routing:
var orders = app.MapGroup("/api/orders").RequireAuthorization();
orders.MapGet("/{id:int}", (int id, IOrderService svc) =>
svc.GetById(id) is Order o ? Results.Ok(o) : Results.NotFound());
| Dimension | Controllers | Minimal APIs |
|---|---|---|
| Performance | Slightly higher overhead | Faster startup and throughput |
| Organization | Natural grouping per class | Route groups + extension methods |
| Filter pipeline | Full MVC filters (auth, resource, action, exception, result) | Endpoint filters only (lighter) |
| Validation | Auto via [ApiController] | Manual (.NET 6-9); auto in .NET 10 |
| AOT support | Not supported | Full (with RDG) |
| OpenAPI | Attributes + ApiExplorer | Built-in AddOpenApi() (.NET 9+) |
Use Controllers when: OData, JsonPatch, complex model binding, large teams with MVC experience. Use Minimal APIs when: New projects, microservices, performance-critical, Native AOT required.
Both coexist in the same app -- migrate incrementally.
// Register ProblemDetails service
builder.Services.AddProblemDetails(options =>
{
options.CustomizeProblemDetails = ctx =>
{
ctx.ProblemDetails.Extensions["traceId"] =
Activity.Current?.Id ?? ctx.HttpContext.TraceIdentifier;
};
});
// IExceptionHandler (.NET 8+) -- structured exception handling
public class GlobalExceptionHandler : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(
HttpContext httpContext, Exception exception, CancellationToken ct)
{
httpContext.Response.StatusCode = 500;
await httpContext.Response.WriteAsJsonAsync(new ProblemDetails
{
Title = "Internal Server Error",
Status = 500
}, ct);
return true;
}
}
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
app.UseExceptionHandler(_ => { });
// Bind configuration section to strongly-typed options
builder.Services.AddOptions<OrderServiceOptions>()
.Bind(builder.Configuration.GetSection("OrderService"))
.ValidateDataAnnotations()
.ValidateOnStart();
// IOptions<T> -- Singleton, reads once at startup
// IOptionsSnapshot -- Scoped, re-reads per request
// IOptionsMonitor -- Singleton, reflects changes via OnChange callback
Controllers use [FromBody], [FromQuery], [FromRoute], [FromHeader], [FromForm], [FromServices]. The [ApiController] attribute enables automatic inference and 400 responses on invalid model state.
Minimal APIs infer binding sources automatically: route template parameters from route, simple types from query string, complex types from body JSON, registered services from DI.
Request ->
[Authorization Filters]
[Resource Filters - Before]
[Model Binding]
[Action Filters - Before]
[Action Method]
[Action Filters - After]
[Result Filters - Before/After]
<- Response
[Exception Filters]
builder.Services.AddKeyedSingleton<ICache, MemoryCache>("memory");
builder.Services.AddKeyedSingleton<ICache, RedisCache>("redis");
app.MapGet("/data", ([FromKeyedServices("redis")] ICache cache) =>
cache.Get("key"));
Route to version-specific agents when the question involves features introduced in a specific .NET release:
| Version | Status | Route To | Key Features |
|---|---|---|---|
| .NET 8 | LTS (Nov 2023 - Nov 2026) | dotnet-8/SKILL.md | Native AOT, Identity API, output caching, keyed DI, IExceptionHandler, metrics |
| .NET 9 | STS (Nov 2024 - May 2026) | dotnet-9/SKILL.md | Built-in OpenAPI, HybridCache, MapStaticAssets, SignalR AOT |
| .NET 10 | LTS (Nov 2025 - Nov 2028) | dotnet-10/SKILL.md | OpenAPI 3.1, built-in validation, SSE TypedResults, Aspire 13, .NET 8 migration |
Enterprise migration path: .NET 8 LTS -> .NET 10 LTS (skip .NET 9 STS).
| Topic | Route To |
|---|---|
| Minimal APIs deep dive (parameter binding, filters, route groups, organizing at scale, controllers vs minimal) | minimal-apis/SKILL.md |
| Model | Server | Use Case | |---|---|---| | In-process (IIS) | IISHttpServer | Windows/IIS, highest throughput | | Out-of-process (IIS) | Kestrel behind IIS | Process isolation | | Self-hosted | Kestrel behind Nginx/YARP | Linux, containers | | Docker | Kestrel | Cloud-native, Kubernetes |
Docker default port changed to 8080 in .NET 8 (non-root). Use ASPNETCORE_HTTP_PORTS=8080.
| Feature | .NET 8 | .NET 9 | .NET 10 | |---|---|---|---| | Minimal APIs + Route Groups | Yes | Yes | Yes | | Keyed DI | Yes | Yes | Yes | | Native AOT (Minimal APIs) | Partial | Partial | Expanded | | Built-in OpenAPI | No | Yes (3.0) | Yes (3.1 + YAML) | | Built-in Validation (Minimal) | No | No | Yes | | HybridCache | No | Preview | Stable | | IExceptionHandler | Yes | Yes | Yes | | Server-Sent Events | No | No | Yes | | HTTP/3 | Stable | Stable | Stable |
Load these for deep knowledge on specific topics:
references/architecture.md -- Middleware pipeline internals, DI container patterns, Kestrel configuration, routing engine, filter pipeline, hosting models. Load when: architecture questions, middleware ordering, DI lifetime issues, Kestrel tuning, reverse proxy setup.references/best-practices.md -- Configuration patterns, security hardening, performance tuning, testing strategies, deployment patterns. Load when: "how should I configure", security review, performance optimization, CI/CD setup.references/diagnostics.md -- Common errors and fixes, middleware ordering bugs, DI resolution failures, authentication debugging, performance profiling. Load when: troubleshooting errors, debugging auth issues, diagnosing performance problems.Ready-made dotnet CLI audit (read-only) in scripts/.
scripts/01-project-audit.sh -- Target frameworks, vulnerable/deprecated/outdated packages, build healthtools
kubectl command-line usage and scripting: kubeconfig and context management, output formats (jsonpath, custom-columns, go-template), all major verbs (get, describe, apply, delete, exec, logs, port-forward, rollout, scale, drain), workload resources, config/storage, networking, RBAC, node management, debugging (CrashLoopBackOff, ImagePullBackOff, OOMKilled), and scripting patterns (dry-run, diff, wait, jq, kustomize). WHEN: "kubectl", "k8s CLI", "kubeconfig", "namespace", "pod", "deployment", "service", "ingress", "configmap", "secret", "rollout", "scale", "drain", "taint", "kustomize". Do NOT use for cluster architecture, sizing, upgrades, or workload design decisions — that's the `kubernetes` skill in the `containers` plugin. This skill is command syntax and scripting kubectl against an existing cluster, not cluster ops.
tools
Bash 5.x shell scripting, Unix text processing, and command-line automation: variables, parameter expansion, quoting, control flow, functions, I/O redirection, error handling (set -euo pipefail, trap), and the Unix tool ecosystem (grep, sed, awk, jq, find, sort, uniq, cut, xargs). Covers process management, networking (curl, ssh, rsync, nc), file locking (flock), parallel execution, and production script patterns. WHEN: "Bash", "bash", "shell", "sh", ".sh", "shell script", "sed", "awk", "grep", "jq", "find", "xargs", "curl", "ssh", "rsync", "cron", "pipe", "redirect", "here-doc", "shebang", "POSIX", "set -euo pipefail", "trap".
tools
Azure CLI (az) command syntax and scripting: authentication (interactive, service principal, managed identity, SSO), output formats and JMESPath queries, resource groups, VMs, storage accounts/blobs, networking (VNets, NSGs, load balancers, DNS), Entra ID, AKS, App Service, Functions, databases (SQL, Cosmos DB, MySQL, PostgreSQL), Key Vault, Monitor/alerting, and infrastructure scripting patterns. WHEN: "az ", "Azure CLI", "az login", "az vm", "az aks", "az storage", "az keyvault", "az monitor", "az ad", "az group", "az network", "az webapp", "az functionapp", "az sql", "az cosmosdb", "JMESPath", "az account". Do NOT use for Azure architecture, landing zones, or multi-subscription strategy — that's the `cloud-platforms` plugin. This skill is about command syntax and scripting the CLI, not deciding what to provision.
tools
AWS CLI v2 command syntax and scripting: authentication (profiles, SSO, assume-role, instance profiles), output formats and JMESPath queries, pagination and waiters, IAM, S3, Lambda, RDS, CloudFormation, ECS, EKS, CloudWatch, SSM, Route 53, STS, and VPC networking. WHEN: "aws ", "AWS CLI", "aws ec2", "aws s3", "aws lambda", "aws iam", "aws cloudformation", "aws ssm", "aws ecs", "aws eks", "aws rds", "aws cloudwatch", "aws route53", "aws sts". Do NOT use for AWS architecture, service selection, multi-account strategy, or FinOps — that's the `cloud-platforms` plugin. This skill is about command syntax and scripting the CLI, not deciding what to provision.