Skip to content
dotnet-best-practices logo

.NET/C# Best Practices

dotnet-best-practices

Validate .NET/C# code against comprehensive best practices for your solution and project.

github/awesome-copilot15.5Kinstalls39.7Kstars.NET & C#

SKILL.md

Full skill instructions

.NET/​C# Best Practices

Your task is to ensure .NET/​C# code in ${selection} meets the best practices specific to this solution/​project. This includes:

Documentation & Structure

  • Create comprehensive XML documentation comments for all public classes, interfaces, methods, and properties
  • Include parameter descriptions and return value descriptions in XML comments
  • Follow the established namespace structure: {Core|Console|App|Service}.{Feature}

Design Patterns & Architecture

  • Use primary constructor syntax for dependency injection (e.g., public class MyClass(IDependency dependency))
  • Implement the Command Handler pattern with generic base classes (e.g., CommandHandler<TOptions>)
  • Use interface segregation with clear naming conventions (prefix interfaces with 'I')
  • Follow the Factory pattern for complex object creation.

Dependency Injection & Services

  • Use constructor dependency injection with null checks via ArgumentNullException
  • Register services with appropriate lifetimes (Singleton, Scoped, Transient)
  • Use Microsoft.Extensions.DependencyInjection patterns
  • Implement service interfaces for testability

Resource Management & Localization

  • Use ResourceManager for localized messages and error strings
  • Separate LogMessages and ErrorMessages resource files
  • Access resources via _resourceManager.GetString("MessageKey")

Async/​Await Patterns

  • Use async/​await for all I/​O operations and long-running tasks
  • Return Task or Task<T> from async methods
  • Use ConfigureAwait(false) where appropriate
  • Handle async exceptions properly

Testing Standards

  • Use MSTest framework with FluentAssertions for assertions
  • Follow AAA pattern (Arrange, Act, Assert)
  • Use Moq for mocking dependencies
  • Test both success and failure scenarios
  • Include null parameter validation tests

Configuration & Settings

  • Use strongly-typed configuration classes with data annotations
  • Implement validation attributes (Required, NotEmptyOrWhitespace)
  • Use IConfiguration binding for settings
  • Support appsettings.json configuration files

Semantic Kernel & AI Integration

  • Use Microsoft.SemanticKernel for AI operations
  • Implement proper kernel configuration and service registration
  • Handle AI model settings (ChatCompletion, Embedding, etc.)
  • Use structured output patterns for reliable AI responses

Error Handling & Logging

  • Use structured logging with Microsoft.Extensions.Logging
  • Include scoped logging with meaningful context
  • Throw specific exceptions with descriptive messages
  • Use try-catch blocks for expected failure scenarios

Performance & Security

  • Use C# 12+ features and .NET 8 optimizations where applicable
  • Implement proper input validation and sanitization
  • Use parameterized queries for database operations
  • Follow secure coding practices for AI/​ML operations

Code Quality

  • Ensure SOLID principles compliance
  • Avoid code duplication through base classes and utilities
  • Use meaningful names that reflect domain concepts
  • Keep methods focused and cohesive
  • Implement proper disposal patterns for resources

More .NET & C# skills

Ready-to-use prompts for comprehensive .NET framework upgrade analysis and execution

39.7K 11.2K
View
csharp-async logo
.NET & C#

csharp-async

Best practices guide for C# asynchronous programming patterns and pitfalls.

39.7K 10.8K
View
csharp-xunit logo
.NET & C#

csharp-xunit

Comprehensive XUnit testing guide covering standard facts, data-driven theories, and best practices.

39.7K 10.3K
View
csharp-docs logo
.NET & C#

csharp-docs

XML documentation standards and patterns for C# public APIs and members.

39.7K 9.7K
View

Add Azure App Insights telemetry to ASP.NET Core or Node.js webapps hosted in Azure.

39.7K 9.7K
View
copilot-sdk logo
.NET & C#

copilot-sdk

Programmatic agent runtime for embedding Copilot's agentic workflows in applications across Python, TypeScript, Go, and .NET.

39.7K 9.5K
View

ASP.NET Minimal API endpoints with automatic OpenAPI/Swagger documentation and strong typing.

39.7K 9.2K
View

Comprehensive guide for building Blazor apps with Microsoft Fluent UI components.

39.7K 9.1K
View
csharp-nunit logo
.NET & C#

csharp-nunit

NUnit best practices for standard and data-driven unit testing in .NET projects.

39.7K 9K
View

Generate Dockerfile and .dockerignore files customized for ASP.NET Core containerization.

39.7K 9K
View
csharp-mstest logo
.NET & C#

csharp-mstest

Modern unit testing with MSTest 3.x/4.x using current APIs and best practices.

39.7K 9K
View
csharp-tunit logo
.NET & C#

csharp-tunit

Best practices for writing unit tests with TUnit, including data-driven and advanced testing patterns.

39.7K 8.9K
View

Coding & apps AI tools

Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View
Imagica logo
Coding & apps

Imagica

Build a no-code AI app in minutes.

Freemium
View
E
Coding & apps

Emergent.sh

An IDE for code migration from legacy to modern frameworks through coding agents.

Freemium
View
Wonder Dynamics logo
Coding & apps

Wonder Dynamics

Automate CGI animation in live-action scenes

Paid
View
M
Coding & apps

Mixo

Launch a website in seconds with AI.

Paid
View
AI Code Convert logo
Coding & apps

AI Code Convert

Streamline Your Coding Experience with AI Code Helper

Free
View