dotnet-backend-patterns
Master C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing
By wshobson · 17,525 installs
npx skills add wshobson/agents --skill dotnet-backend-patterns
Source repository · Upstream listing
.NET Backend Development Patterns
Master C /.NET patterns for building production grade APIs, MCP servers, and enterprise backends with modern best practices (2024/2025).
When to Use This Skill
Developing new .NET Web APIs or MCP servers
Reviewing C code for quality and performance
Designing service architectures with dependency injection
Implementing caching strategies with Redis
Writing unit and integration tests
Optimizing database access with EF Core or Dapper
Configuring applications with IOptions pattern
Handling errors and implementing resilience patterns
Core Concepts
1. Project Structure (Clean Architecture)
2. Dependency Injection Patterns
3. Async/Await Patterns
4. Configuration with IOptions
5. Result Pattern (Avoiding Exceptions for Flow Control)
Data Access Patterns
Entity Framework Core
Dapper for Performance
Caching Patterns
Multi Level Cache with Redis
Testing Patterns
Unit Tests with xUnit and Moq
Integration Tests with WebApplicationFactory
Best Practices
DO
1. Use async/await all the way through the call stack
2. Inject dependencies through constructor injection
3. Use IOptions<T for typed configuration
4. Return Result types instead of throwing exceptions for business logic
5. Use CancellationToken in all async methods
6. Prefer Dapper for read heavy, performance critical queries
7. Use EF Core for complex domain models with change tracking
8. Cache aggressively with proper invalidation strategies
9. Write unit tests for business logic, integration tests for APIs
10. Use record types for DTOs and immutable data
DON'T
1. Don't block on async with .Result or .Wait()
2. Don't use async void except for event handlers
3. Don't catch generic Exception without re throwing or logging
4. Don't hardcode configuration values
5. Don't expose EF entities directly in APIs (use DTOs)
6. Don't forget AsNoTracking() for read only queries
7. Don't ignore CancellationToken parameters
8. Don't create new HttpClient() manually (use IHttpClientFactory)
9. Don't mix sync and async code unnecessarily
10. Don't skip validation at API boundaries
Common Pitfalls
N+1 Queries : Use .Include() or explicit joins
Memory Leaks : Dispose IDisposable resources, use using
Deadlocks : Don't mix sync and async, use ConfigureAwait(false) in libraries
Over fetching : Select only needed columns, use projections
Missing Indexes : Check query plans, add indexes for common filters
Timeout Issues : Configure appropriate timeouts for HTTP clients
Cache Stampede : Use distributed locks for cache population