aspnet-core-standards
Use when building or reviewing an ASP.NET Core (.NET 8/9) HTTP service in a touchstone repo — minimal APIs vs controllers, DI lifetimes, options/config, ProblemDetails, EF Core, auth policies, middleware, resilience, integration tests. Triggers on `Microsoft.AspNetCore` in a .csproj, `WebApplication.CreateBuilder` / `app.MapGet` in Program.cs, `[ApiController]` controllers, `DbContext`. C#-language rules (nullable, async, analyzers, packaging) live in the csharp skill.
- License 许可
- MIT
- 最近更新
- 2026-08-26
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- aspnet-core-standards
- license
- MIT
- metadata
- { "author": "touchstone", "version": "0.2.0" }
- description
- Use when building or reviewing an ASP.NET Core (.NET 8/9) HTTP service in a touchstone repo — minimal APIs vs controllers, DI lifetimes, options/config, ProblemDetails, EF Core, auth policies, middleware, resilience, integration tests. Triggers on `Microsoft.AspNetCore` in a .csproj, `WebApplication.CreateBuilder` / `app.MapGet` in Program.cs, `[ApiController]` controllers, `DbContext`. C#-language rules (nullable, async, analyzers, packaging) live in the csharp skill.
03 SKILL.md 正文
ASP.NET Core (framework)
Full standard: standards/frameworks/aspnet-core.md (layers on standards/languages/csharp.md).
This skill inlines the load-bearing rules so it stays useful when installed standalone in
~/.claude/skills/:
Always
- Minimal APIs by default;
[ApiController]MVC when the surface is richer. Endpoints stay thin (validate → service → result), grouped withMapGroupcarrying shared auth/filters/tags. - Organize by feature / vertical slice, not technical layers; register each feature behind one
Add*extension; keepProgram.csthin. - DI lifetimes:
DbContextand per-request work are scoped; never inject scoped into a singleton; keepValidateScopes/ValidateOnBuildon. - Options pattern for all config — bind typed
IOptions<T>,.ValidateOnStart(). No scatteredEnvironment.GetEnvironmentVariable. - No secrets in the repo:
dotnet user-secretsin dev, Key Vault / Secrets Manager + Managed Identity in prod. - Async to the wire: flow
CancellationTokento EF/HttpClient/downstream; no sync-over-async (.Result/.Wait()).
Don't get burned
- Bind requests to DTOs, never to EF entities (over-posting). Validate with DataAnnotations/FluentValidation;
[ApiController]auto-400s. - Errors are
ProblemDetails(RFC 9457):AddProblemDetails()+UseExceptionHandler()+ oneIExceptionHandlermapping domain errors → status. No stack traces in prod (dev exception page isIsDevelopment()-only). - EF: migrations reviewed + applied at deploy — never
Migrate()/EnsureCreated()on startup.AsNoTracking()on reads; kill N+1 withInclude/.Selectprojections;DbContextis not thread-safe. - Deny by default: set a fallback authorization policy requiring an authenticated user; opt out with
[AllowAnonymous]. Validate JWT issuer/audience. Policies named, not inline role strings. - Middleware order is behavior:
UseRouting → UseCors → UseAuthentication → UseAuthorization. NeverAllowAnyOrigin()+AllowCredentials(). - Outbound HTTP via
IHttpClientFactorytyped clients (nevernew HttpClient()); addAddStandardResilienceHandler()(retry/timeout/circuit-breaker).
Defer (don't duplicate)
- C# language (nullable, async, analyzers, CPM, packaging) →
../../standards/languages/csharp.md; API contract/errors →../../standards/design/api-design.md; schema + EF migrations →../../standards/platform/database.md; authZ policy/OWASP →../../standards/practices/app-security.md; OpenTelemetry →../../standards/platform/observability.md; retry/timeout budgets →../../standards/design/resilience.md; test pyramid →../../standards/practices/testing-strategy.md.
Done
Minimal-API/controller endpoints thin · feature slices · scoped DbContext, no scoped-into-singleton · typed options ValidateOnStart · no repo secrets · DTO-bound + validated, ProblemDetails errors · EF migrations at deploy, AsNoTracking, N+1 guarded · deny-by-default auth, JWT validated · middleware order correct, explicit CORS · CancellationToken to the wire · OpenTelemetry exported · IHttpClientFactory + resilience handler · WebApplicationFactory + Testcontainers integration tests. See standards/frameworks/aspnet-core.md.
04 同仓库更多 Skills
ok-standards
Use when writing shell, per standards/languages/shell.md.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.
demo-standards
Use when editing demo code in a touchstone fixture repo, a deliberately ordinary description that is long enough to clear the forty character minimum.