dotnet-patterns
Idiomatic C# and .NET patterns, conventions, dependency injection, async/await, and best practices for building robust, maintainable .NET applications. Use when writing or reviewing C# / .NET code — DI, async, or general conventions.
By affaan-m · 2,905 installs
npx skills add affaan-m/ecc --skill dotnet-patterns
Source repository · Upstream listing
.NET Development Patterns
Idiomatic C and .NET patterns for building robust, performant, and maintainable applications.
When to Activate
Writing new C code
Reviewing C code
Refactoring existing .NET applications
Designing service architectures with ASP.NET Core
Core Principles
1. Prefer Immutability
Use records and init only properties for data models. Mutability should be an explicit, justified choice.
2. Explicit Over Implicit
Be clear about nullability, access modifiers, and intent.
3. Depend on Abstractions
Use interfaces for service boundaries. Register via DI container.
Async/Await Patterns
Proper Async Usage
Parallel Async Operations
Options Pattern
Bind configuration sections to strongly typed objects.
Result Pattern
Return explicit success/failure instead of throwing for expected failures.
Repository Pattern with EF Core
Middleware and Pipeline
Minimal API Patterns
Guard Clauses
Anti Patterns to Avoid
Anti Pattern Fix
async void methods Return Task (except event handlers)
.Result or .Wait() Use await
catch (Exception) { } Handle or rethrow with context
new Service() in constructors Use constructor injection
public fields Use properties with appropriate accessors
dynamic in business logic Use generics or explicit types
Mutable static state Use DI scoping or ConcurrentDictionary
string.Format in loops Use StringBuilder or interpolated string handlers