dotnet-patterns
/dotnet-patterns
Use when writing C#/.NET backend code — ASP.NET Core APIs (minimal APIs or MVC), workers, EF Core data access. Builder playbook: layout, DI lifetimes, async/cancellation, EF Core discipline, options pattern, error contract, testing shape. Complements csharp-reviewer.
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 24.09.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when writing C#/.NET backend code — ASP.NET Core APIs (minimal APIs or MVC), workers, EF Core data access. Builder playbook: layout, DI lifetimes, async/cancellation, EF Core discipline, options pattern, error contract, testing shape. Complements csharp-reviewer.
Original author description
Use when writing C#/.NET backend code — ASP.NET Core APIs (minimal APIs or MVC), workers, EF Core data access. Builder playbook: layout, DI lifetimes, async/cancellation, EF Core discipline, options pattern, error contract, testing shape. Complements csharp-reviewer.
How it works
- Layout
- DI lifetimes (the classic traps)
- Async all the way
- EF Core discipline
- Config — options pattern
- Error contract
- Testing shape
SKILL.md preview
--- name: dotnet-patterns description: Use when writing C#/.NET backend code — ASP.NET Core APIs (minimal APIs or MVC), workers, EF Core data access. Builder playbook: layout, DI lifetimes, async/cancellation, EF Core discipline, options pattern, error contract, testing shape. Complements csharp-reviewer. --- # C#/.NET Backend Patterns ## Layout - Vertical slices (feature folders: endpoint + handler + models per feature) for API-shaped services; full Clean Architecture layering only when the domain genuinely warrants it — record the choice as an ADR either way. - Minimal APIs for small/medium surfaces; MVC controllers when filters/model-binding complexity earns it. ## DI lifetimes (the classic traps) - Scoped services must NEVER be captured by singletons (captive dependency — resolve via `IServiceScopeFactory` inside the singleton instead). - `HttpClient` via `IHttpClientFactory`, never `new HttpClient()` per call (socket exhaustion). - Register by interface at the boundary you intend to fake in tests; concrete elsewhere is fine. ## Async all the way - No `.Result`/`.Wait()`/`GetAwaiter().GetResult()` on async paths — deadlock and threadpool starvation fuel. - `CancellationToken` flows from the endpoint through every service and EF call: `await db.Orders.ToListAsync(ct)`. Endpoints accept it; libraries propagate it. - `ValueTask` only where profiling justifies it; default is `Task`. ## EF Core discipline - Reads: `AsNoTracking()` by default; project to DTOs with `Select` — never return entities from queries that don't update. - No lazy-loading proxies: load explicitly (`Include`) so every query's shape is visible — N+1 becomes impossible to miss. - Migrations: one migration per change, reviewed like code; destructive column changes follow expand-contract (see db-optimization skill). - Transactions explicit where multi-write consistency matters (`ExecutionStrategy` + `TransactionScope`-free patterns with `BeginTransactionAsync`). ## Config — options pattern - `IOptions<T>` with `ValidateDataAnnotations().ValidateOnStart()` — invalid config fails the boot, not the first request. - Secrets from user-secrets/KeyVault/env — never appsettings committed values. ## Error contract - `ProblemDetails` (RFC 9457) via `AddProblemDetails()`; exceptions mapped centrally (exception handler middleware), typed domain exceptions → status codes. No try/catch per controller. - Nullable reference types ON project-wide; warnings as errors for new code. ## Testing shape - xUnit; unit tests fake at the interface boundary. - `WebApplicationFactory<Program>` for integration tests over the real pipeline (routing, filters, serialization) with a test database (Testcontainers where Docker exists). - Snapshot the API surface where the contract matters (Verify/ApiApprovals) so drift is a failing test.
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · jdanigo/hydraia | 90 | MIT |
| affaan-m/ECC | 100 | MIT |
| SHRIJANAGAIN/Nemo-Cli | 100 | Apache-2.0 |
| j4flmao/agent-skills | 95 | MIT |
Database snapshot: 13.11.2026 · package version f6b575d8b987 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100csharp-dotnet
Use when writing, reviewing, testing, or shipping C# / .NET code — ASP.NET Core APIs (minimal APIs vs controllers), EF Core data access, async correctness, solution layout in .cs/.csproj/.sln. NOT a Java/Spring backend (that is spring-boot), NOT a Node/TypeScript backend (that… - 100csharp-dotnet
C# and .NET patterns for OpenClaw. Triggers when writing C#, implementing .NET APIs, working with EF Core, or making architecture decisions in .NET projects. Use for: Clean Architecture, dependency injection, async patterns, Result pattern, Minimal APIs, EF Core queries, and unit testing in C#. - 90dotnet-minimal-apis
Build ASP.NET Core minimal APIs with organized endpoint groups, filters, typed results, and a clear line to MVC. Use when structuring .NET HTTP services or deciding between minimal APIs and controllers. - 90dotnet-backend-patterns
Provides .NET and ASP.NET Core patterns for REST APIs, Entity Framework, dependency injection, and middleware. Use when working with C# files (*.cs, *.csproj) or when the user mentions .NET, ASP.NET Core, C#, or Entity Framework. - 100neo-dotnet
Use this skill when the user asks broad .NET questions or the project contains .sln/.csproj files and the exact ASP.NET/EF/C# subdomain is not yet clear. Detect the SDK/project shape, run or recommend .NET CLI commands, and route to Minimal APIs, Web API, MVC, Tag Helper, EF… - 100dotnet-core-expert
Use when building .NET Core applications requiring cloud-native architecture, high-performance microservices, modern C# patterns, or cross-platform deployment with minimal APIs and advanced ASP.NET Core features.