dotnet-patterns

Implements idiomatic C# and .NET patterns for dependency injection, async code, and ASP.NET Core services.

Updated May 19, 2026
One-click install
npx skills add https://github.com/azusagasaku/--claude-config --skill dotnet-patterns-azusagasaku
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-patterns
Source: https://github.com/azusagasaku/--claude-config/tree/main/skills/ecc/dotnet-patterns
Command: npx skills add https://github.com/azusagasaku/--claude-config --skill dotnet-patterns-azusagasaku

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing C# and .NET code without established conventions leads to mutable models, blocking async calls, untestable services, and configuration scattered across string keys. This Skill provides a consistent set of idiomatic patterns so .NET applications stay maintainable, testable, and free of common pitfalls like deadlocks and swallowed exceptions. ## Core Features & Use Cases - Async/Await Patterns: Enforces async-all-the-way with CancellationToken support and parallel operations via Task.WhenAll, avoiding deadlock-prone .Result and .Wait() calls. - Architecture Patterns: Covers dependency injection with interface-based abstractions, the Options pattern for strongly-typed configuration, the Result pattern for explicit success/failure, and repository pattern implementations with EF Core. - ASP.NET Core Guidance: Includes middleware pipelines, Minimal API route groups, guard clauses, and an anti-patterns table with concrete fixes. - Use Case: When refactoring a legacy ASP.NET Core service that blocks on async calls and uses mutable DTOs, apply these patterns to convert it to immutable records, constructor injection, and proper async flows. ## Quick Start Review my C# OrderService class and refactor it to follow idiomatic .NET patterns including async best practices and dependency injection.

Frequently Asked Questions about dotnet-patterns

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

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

Avoid deadlocks by using async all the way through the call stack and never blocking with .Result or .Wait(). Pass a CancellationToken through every async method and use Task.WhenAll for independent parallel operations.

What is the Options pattern in ASP.NET Core?▼

The Options pattern binds configuration sections to strongly-typed classes registered via builder.Services.Configure<T>(). Inject IOptions<T> into services to access validated settings instead of reading raw string keys from IConfiguration.

Should I use records or classes for C# data models?▼

Use records and init-only properties for data models and DTOs to enforce immutability by default. Reserve mutable classes with public setters for cases where mutation is an explicit, justified design choice.

When should I use the Result pattern instead of exceptions?▼

Use the Result pattern for expected failures like validation errors, returning explicit success or failure values. Reserve exceptions for truly exceptional conditions such as null arguments or infrastructure failures.

How do I write a repository with EF Core correctly?▼

Inject AppDbContext via the constructor, use AsNoTracking() for read queries, and pass CancellationToken to all async EF Core methods. Register the repository interface with AddScoped so the DbContext lifetime aligns with the request scope.

Why is async void considered an anti-pattern in C#?▼

async void methods cannot be awaited, swallow exceptions that crash the process, and make error handling impossible. Return Task instead, except for event handlers where the signature is fixed by the framework.