dotnet-patterns

Standardize idiomatic C# and .NET coding patterns for services and APIs.

Updated May 11, 2026
One-click install
npx skills add https://github.com/CZ-X-Ya/oh-my-csharp-skills --skill dotnet-patterns-cz-x-ya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-patterns
Source: https://github.com/CZ-X-Ya/oh-my-csharp-skills/tree/main/dotnet-patterns
Command: npx skills add https://github.com/CZ-X-Ya/oh-my-csharp-skills --skill dotnet-patterns-cz-x-ya

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you avoid common .NET design and implementation pitfalls by applying idiomatic C# patterns that improve maintainability, correctness, and performance.

Core Features & Use Cases

  • Immutability-first models: Use records and init-only properties to reduce bugs from unintended state changes.
  • Clear intent and boundary safety: Prefer explicit nullability, access modifiers, and dependency injection via abstractions.
  • Reliable async and HTTP/API design: Follow async/await best practices (including cancellation and concurrency) and use consistent patterns for ASP.NET Core pipelines and minimal APIs.

Use Case: When building an ASP.NET Core service, you can refactor an existing controller/service layer to use immutable request/response models, DI-based repository abstractions, and correct async flows (with cancellation and parallelism where appropriate) to make the system more robust and easier to review.

Quick Start

Apply the patterns from dotnet-patterns to your current C# service code by refactoring your models for immutability and updating your services to use explicit nullability, constructor injection, and safe async/await with cancellation.

Frequently Asked Questions about dotnet-patterns

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

FAQPage Schema
What are the best async await patterns for ASP.NET Core services?

ASP.NET Core services should follow async/await best practices including proper cancellation token propagation and safe concurrency management to ensure reliable HTTP/API design and prevent deadlocks.

How do I refactor C# models for immutability?

Refactor C# models for immutability by using records and init-only properties, reducing bugs from unintended state changes while enforcing clear boundary safety through explicit nullability and access modifiers.

Does dependency injection via abstractions work with minimal APIs?

Dependency injection via abstractions works with minimal APIs by applying consistent patterns for ASP.NET Core pipelines and constructor injection, standardizing idiomatic coding patterns for maintainable endpoints.

What is the best way to structure EF Core repository patterns?

The best way to structure EF Core repository patterns is by using DI-based repository abstractions with explicit nullability and immutability-first models, standardizing data access structure and middleware composition.

Why should I use options and result patterns in C#?

Use options and result patterns in C# to improve correctness and explicitness, reducing unhandled exceptions and null reference bugs while making business logic refactoring safer and easier to review.