Skip to content
Back to skills

Aspnetcore Patterns

ASecurity

Designs ASP.NET Core application composition, middleware, dependency injection, controllers, hosting, options, authentication, and authorization. Use for application-wide web-host concerns; do not use for Minimal API endpoint design (use minimal-api-patterns) or standalone contract review (use api-contract-review).

  • 7 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
ai-agentstestingcode-reviewapisecurityperformance

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add k4ndev/claude-code-dotnet --skill aspnetcore-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Aspnetcore Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Aspnetcore Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/k4ndev-aspnetcore-patterns/badge)](https://www.skillsdirectory.com/skills/k4ndev-aspnetcore-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: aspnetcore-patterns
description: Designs ASP.NET Core application composition, middleware, dependency injection, controllers, hosting, options, authentication, and authorization. Use for application-wide web-host concerns; do not use for Minimal API endpoint design (use minimal-api-patterns) or standalone contract review (use api-contract-review).
---

# ASP.NET Core Patterns

## Purpose
Build web-host behavior with correct middleware order, DI lifetimes, configuration validation, security boundaries, and operations readiness.

## Scope
Application-level ASP.NET Core composition, MVC/controllers, middleware, options, outbound HTTP clients, health checks, and hosting. Minimal API endpoint shape belongs to `minimal-api-patterns`.

## When to use
- A task concerns middleware ordering, DI, configuration, controller organization, authentication setup, or web-host readiness.
- A web app needs an integration-testing strategy for host-level behavior.

## Do not use for
- A Minimal API route handler/group as the primary subject: use `minimal-api-patterns`.
- API compatibility/status semantics only: use `api-contract-review`.
- Threat modeling across the whole application: coordinate with `security-audit`.

## Required context
Inspect target framework/package versions, `Program.cs`, middleware order, registrations and service lifetimes, options/configuration sources, auth policies, controllers, error contract, deployment model, and existing integration tests.

## Workflow
1. Map request flow from server to exception handling, routing, authentication, authorization, endpoint, and response; compare actual middleware order with the app's requirements.
2. Trace service lifetimes. A singleton must not capture a scoped service; do not solve it by turning request state into singleton state.
3. Bind critical options and validate them at startup (for supported target versions, `ValidateOnStart`); avoid logging secret values.
4. Keep controllers focused on HTTP concerns and use explicit request/response DTOs at external boundaries.
5. Enforce authorization server-side, including resource ownership; CORS is not authorization.
6. Use `IHttpClientFactory` or typed clients for outbound HTTP; configure timeouts/resilience intentionally and avoid unbounded retries.
7. Return the established error contract/ProblemDetails without stack traces or infrastructure details; bound request size and pagination.
8. Add host-level integration tests for the changed middleware, auth, serialization, or routing behavior; check health readiness semantics.

## Decision rules
- Preserve existing architecture and error conventions unless they are demonstrably unsafe.
- Use middleware for cross-cutting request-pipeline behavior, filters for narrower MVC behavior, and application services for business logic.
- Verify .NET/package versions before relying on framework APIs; do not infer security from CORS or client-side hiding.

## Expected output format
State request/host flow, lifetime/configuration/security risks, the minimal code or registration change, relevant version constraints, and integration tests. Identify unverified environment assumptions.

## Common mistakes
- Registering a scoped repository in a singleton, placing authorization before authentication, exposing detailed errors, or binding unvalidated secrets/options.
- Creating `new HttpClient()` per operation, using CORS as access control, and testing middleware only with isolated unit tests.

## Edge cases
- Startup validation may delay host startup by design; explain rollout implications.
- `IOptionsSnapshot<T>` is scoped and unsuitable for singleton consumption; `IOptionsMonitor<T>` has different change semantics.
- Blazor Server/Interactive Server combines UI concerns with an HTTP host; classify the actual hosting model.

## Examples
See [ASP.NET Core examples](examples.md) for validated options and safe outbound clients.

## Test scenarios
- Positive: “Our singleton hosted service captures a scoped DbContext; propose a safe design.”
- Negative: “Optimize this EF query's projection” routes to `efcore-patterns` / `performance-review`.
- Boundary: “Review this MVC endpoint's response compatibility” selects `api-contract-review` and `dotnet-code-review` only when review intent is present.

## Related skills
`minimal-api-patterns`, `api-contract-review`, `security-audit`, `logging-observability`, `async-concurrency`, `testing-quality`.

Files in this skill

  • SKILL.md4.4 KB
  • examples.md1.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.