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 API architectures.
Author
Category
Development ToolsInstall
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
.NET Backend Development Pattern - A Complete Guide to Building Production-Grade APIs
Skill Overview
Master modern best practices for C#/.NET backend development to build production-grade Web APIs, MCP servers, and enterprise backend applications.
Use Cases
1. Develop .NET Web APIs and MCP Servers
When you need to create a new ASP.NET Core Web API or a Model Context Protocol (MCP) server, this skill provides end-to-end architectural guidance. From project structure design, API endpoint planning, to middleware configuration and error handling, it helps you quickly set up maintainable backend services.
2. C# Code Review and Refactoring
When reviewing team members’ C# code or cleaning up technical debt, this skill helps you identify common issues such as improper dependency injection usage, flaws in asynchronous methods, inefficient database queries, missing caching strategies, and more. It also offers specific improvement suggestions and refactoring plans.
3. Backend Architecture Design and Performance Optimization
When designing service-layer architecture, choosing data access technology (EF Core vs. Dapper), planning caching strategies (Redis), and implementing resilience patterns (retries, circuit breakers, timeouts), this skill provides proven architectural patterns and decision guidelines.
Core Capabilities
1. Dependency Injection and Architectural Patterns
Provides .NET dependency injection best practices, including choosing service lifetimes (Transient, Scoped, Singleton), constructor injection patterns, and identifying service locator anti-patterns. It also covers classic architectural designs such as layered architecture, the repository pattern, and the unit of work pattern.
2. Data Access and Performance Optimization
Covers two main data access technologies: Entity Framework Core and Dapper. Includes: EF Core query optimization (N+1 issues, tracking queries), index design, migration management; Dapper lightweight ORM usage scenarios, batch operations, and multi-table queries. Also covers database connection pool configuration and asynchronous data access.
3. Caching, Configuration, and Testing
Covers implementation strategies for in-memory caching and distributed Redis caching, including cache key design, expiration policies, and cache penetration/breakdown (avalanche) handling. Uses the IOptions configuration pattern to manage application configuration. Includes best practices for xUnit unit tests and integration tests, such as Mock usage, test data management, and test coverage.
Common Questions
How do I choose the lifetime for .NET dependency injection?
Note: Scoped services cannot be injected into Singleton services, otherwise you risk capturing a scoped service incorrectly.
How should I choose between EF Core and Dapper?
A common real-world combination: use EF Core for complex queries and business logic, and use Dapper for high-concurrency read/write and batch operations.
What are common pitfalls of async/await in .NET backends?
Correct async patterns improve server throughput and prevent thread-pool starvation.