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

Install

Hot:5

Download and extract to your skills directory

Copy command and send to OpenClaw for auto-install:

Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-dotnet-backend-patterns&locale=en&source=copy

.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?


  • Transient: A new instance is created every time a request is made. Suitable for stateless services.

  • Scoped: Shared instance within the same HTTP request. Suitable for EF DbContext.

  • Singleton: Only one instance exists for the lifetime of the application. Suitable for caching services and configuration classes.
  • 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?


  • Choose EF Core: Complex queries, need LINQ expressions, frequently changing models, and need migration support.

  • Choose Dapper: Extreme performance requirements, simple CRUD, batch operations, migration of existing SQL scripts.
  • 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?


  • Avoid async void: Use async Task everywhere except for event handlers.

  • Avoid .Result and .Wait(): They can cause deadlocks—always use await.

  • ConfigureAwait(false): Use in library code to reduce context switching.

  • Handle cancellation tokens correctly: Long-running async methods should support CancellationToken.
  • Correct async patterns improve server throughput and prevent thread-pool starvation.