dotnet-patterns

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill dotnet-patterns-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-patterns
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/dotnet-patterns
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill dotnet-patterns-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing and reviewing C# code without consistent conventions leads to mutable models, blocking async calls, and tightly coupled services that are hard to maintain. This Skill provides concrete, idiomatic .NET patterns so generated or reviewed code follows established best practices. ## Core Features & Use Cases - Core Design Patterns: Enforces immutability with records and init-only properties, explicit nullability, and interface-based dependency injection. - Async and API Patterns: Covers proper async/await usage with CancellationToken, parallel operations via Task.WhenAll, Minimal API route groups, and custom middleware. - Use Case: When refactoring an ASP.NET Core service, use this Skill to replace blocking .Result calls with async all the way, introduce the Result pattern for expected failures, and structure EF Core repositories with AsNoTracking queries. ## Quick Start Review this C# OrderService class and refactor it to follow idiomatic .NET patterns including constructor injection, async/await, and guard clauses.

Frequently Asked Questions about dotnet-patterns

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

FAQPage Schema
How do I write async/await code correctly in C#?▼

Use async all the way by returning Task from methods and awaiting calls instead of blocking with .Result or .Wait(). Always accept and pass a CancellationToken, and use Task.WhenAll to run independent operations concurrently.

What is the Result pattern in C# and when should I use it?▼

The Result pattern returns an explicit success or failure object instead of throwing exceptions for expected failures like validation errors. Use it for business-rule failures while reserving exceptions for truly exceptional conditions.

How do I implement the repository pattern with EF Core?▼

Define an interface such as IOrderRepository with async methods accepting CancellationToken, then implement it using AppDbContext with AsNoTracking for read queries. Register the implementation with AddScoped in the DI container.

Why is .Result or .Wait() dangerous in ASP.NET Core?▼

Blocking on async code with .Result or .Wait() risks thread starvation and deadlocks under load. The fix is to make the entire call chain async and await each operation instead of synchronously blocking.

When should I use records versus classes in C#?▼

Use records for immutable value objects and DTOs where equality is value-based, and init-only properties for immutable request models. Reserve mutable classes with public setters for cases where mutation is an explicit, justified choice.