dotnet-backend-patterns

Implements C#/.NET backend patterns for APIs, data access, caching, and testing.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill dotnet-backend-patterns-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-backend-patterns
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/dotnet-backend-patterns
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill dotnet-backend-patterns-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve? Building production-grade .NET backends requires consistent decisions across dependency injection, async programming, data access, caching, and testing. This Skill provides proven C# patterns and templates so you avoid common pitfalls like deadlocks, N+1 queries, and cache stampedes. ## Core Features & Use Cases - Architecture & DI Patterns: Clean Architecture project structure, service lifetime registration, keyed services, and the IOptions configuration pattern for .NET 8+. - Data Access Guidance: Side-by-side EF Core and Dapper implementations covering query optimization, multi-mapping, transactions, bulk operations, and compiled queries. - Caching & Resilience: Multi-level caching with IMemoryCache and Redis, stale-while-revalidate, and the Result pattern for error handling without exceptions. - Testing Templates: xUnit unit tests with Moq and integration tests using WebApplicationFactory with in-memory substitutes. - Use Case: When scaffolding a new ASP.NET Core Web API with SQL Server and Redis, apply the repository and service templates to get a working CRUD layer with validation, caching, and tests. ## Quick Start Ask the AI to generate a .NET product service with Dapper repository, Redis caching, FluentValidation, and xUnit tests following these backend patterns.

Frequently Asked Questions about dotnet-backend-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a .NET Web API with Clean Architecture?

Organize the solution into Domain, Application, Infrastructure, and Api layers. Domain holds entities with no dependencies, Application contains services and DTOs, Infrastructure implements data access and caching, and Api hosts controllers and Program.cs.

Dapper vs EF Core: which should I use for data access?

Use Dapper for performance-critical read-heavy queries, complex SQL with CTEs, and legacy schemas. Use EF Core for rich domain models needing change tracking, LINQ translation, and migrations. Many systems use both side by side.

How do I avoid deadlocks with async/await in C#?

Never block on async code with .Result or .GetAwaiter().GetResult(), and avoid async void except for event handlers. Use async all the way down the call stack and add ConfigureAwait(false) in library code.

How do I fix N+1 query problems in Entity Framework Core?

Use Include() with ThenInclude() to eager-load related entities in a single query. For multiple large collections, add AsSplitQuery() to prevent cartesian explosion, and use AsNoTracking() for read-only queries.

Does .NET dependency injection support multiple implementations of one interface?

Yes, .NET 8+ supports keyed services via AddKeyedScoped, letting you register multiple implementations like Stripe and PayPal processors and resolve them with the FromKeyedServices attribute.

How do I write integration tests for ASP.NET Core APIs?

Use WebApplicationFactory<Program> from Microsoft.AspNetCore.Mvc.Testing and override services in ConfigureServices, replacing the real database with UseInMemoryDatabase and Redis with AddDistributedMemoryCache.