Skip to content
Back to skills

Dotnet Best Practices

ASecurity

ASP.NET Core / C# production best practices: 40 rules in 10 categories (architecture, DI, errors, security, performance, async, EF Core, testing, API, devops) prioritized by impact. Use when writing/reviewing .NET backend code.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 14, 2026
devopsgoc#bashtestinggitapidatabasebackenddevopssecurity

Works with

  • api

Security analysis

A100/100

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

Scanned November 14, 2026

npx -y skills add SebastianLuser/claude-code-arcane --skill dotnet-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Dotnet Best Practices?

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

Security grade badge for Dotnet Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/sebastianluser-dotnet-best-practices/badge)](https://www.skillsdirectory.com/skills/sebastianluser-dotnet-best-practices)

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: dotnet-best-practices
description: "ASP.NET Core / C# production best practices: 40 rules in 10 categories (architecture, DI, errors, security, performance, async, EF Core, testing, API, devops) prioritized by impact. Use when writing/reviewing .NET backend code."
category: "backend"
argument-hint: "[architecture|di|errors|security|performance|async|database|testing|api|all]"
user-invocable: true
allowed-tools: Read, Glob, Grep, Bash, Write, Edit, Task
---
# dotnet-best-practices — Guide prioritized by impact

40 rules for production-ready ASP.NET Core (.NET 10) applications, organized into 10 categories and prioritized from **CRITICAL** to **LOW-MEDIUM**. Each rule in the catalog (in `references/`) comes with its impact, an incorrect example, a correct example and a link to the docs.

## MANDATORY WORKFLOW

**Do not apply the 40 rules blindly. Diagnose first, prioritize by impact.**

### Step 0: Determine scope

1. **New code or an audit of existing code?** If it is an audit, read the target feature/project first.
2. **Which category applies?** Map the problem area (see table) or use `all` for a full review.
3. **Are there concrete symptoms?** (deadlocks, N+1, inconsistent 500s, leaks) → go straight to the relevant category.

### Step 1: Prioritize by impact

Apply in this order — do not drop a level until the previous one is resolved:

| Priority | Category | Impact | Reference |
|-----------|-----------|---------|-----------|
| 1 | Architecture | CRITICAL | `references/architecture.md` |
| 2 | Dependency Injection | CRITICAL | `references/dependency-injection.md` |
| 3 | Async & Concurrency | HIGH | `references/async.md` |
| 4 | Error Handling | HIGH | `references/error-handling.md` |
| 5 | Security | HIGH | `references/security.md` |
| 6 | Performance | HIGH | `references/performance.md` |
| 7 | Database & EF Core | MEDIUM-HIGH | `references/database.md` |
| 8 | Testing | MEDIUM-HIGH | `references/testing.md` |
| 9 | API Design | MEDIUM | `references/api-design.md` |
| 10 | DevOps & Deployment | LOW-MEDIUM | `references/devops.md` |

### Step 2: Apply + verify

For each relevant rule: read the correct example in the reference, apply it, and verify against the closing checklist.

### Step 3: Closing checklist

- [ ] `<Nullable>enable</Nullable>` + warnings as errors; zero `#nullable disable`
- [ ] Async end-to-end with `CancellationToken`; zero `.Result`/`.Wait()`/`.GetAwaiter().GetResult()`
- [ ] Constructor DI with the correct scope; no manual `BuildServiceProvider()` or service locator
- [ ] Errors via `ProblemDetails` (RFC 7807); no exposed stack traces
- [ ] No N+1 in EF Core (`Include`/projection); `AsNoTracking()` on reads
- [ ] Versioned migrations; never `EnsureCreated()` in prod
- [ ] AuthZ through declarative policies; secrets in a secret manager (not in `appsettings.json`)
- [ ] Structured logging (Serilog JSON) + health checks
- [ ] Tests with xUnit; integration against a real Postgres (Testcontainers), not DbContext mocks

If the whole checklist passes → the code is **COMPLIANT**. Before writing significant changes, confirm the approach with the user (Question → Decision → Approval).

## Symptom → category mapping table

| Symptom | Category |
|---------|-----------|
| Deadlocks / thread pool starvation / app hangs | Async, Performance |
| Slow endpoints, many queries | Performance, Database |
| DI `InvalidOperationException` / scopes / captured dependency | DI, Architecture |
| Inconsistent 500 errors / stack trace leaks | Error Handling |
| Exposed endpoints / brute force / sensitive data in logs | Security |
| Brittle tests, or tests that hit real services/DB without control | Testing |
| Inconsistent responses / entity over-fetching | API Design |

## Next steps

To structure the project → `/dotnet-architecture`. To start a new backend with these defaults → `/dotnet-scaffold`.

---

_Adapted from [github/awesome-copilot](https://github.com/github/awesome-copilot) (dotnet-best-practices), [dotnet/skills](https://github.com/dotnet/skills) and [Aaronontheweb/dotnet-skills](https://github.com/Aaronontheweb/dotnet-skills). Reorganized into Arcane's skill+references format._

Files in this skill

  • SKILL.md4.1 KB
  • references/api-design.md2.7 KB
  • references/architecture.md2.6 KB
  • references/async.md2.4 KB
  • references/database.md2.4 KB
  • references/dependency-injection.md2.7 KB
  • references/devops.md2.7 KB
  • references/error-handling.md2.6 KB
  • references/performance.md2.1 KB
  • references/security.md2.7 KB
  • references/testing.md2.5 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 devops →

Comments

Loading comments…

Newsletter

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