Catalog
github/dotnet-best-practices

github

dotnet-best-practices

Ensure .NET/C# code meets best practices for the solution/project.

v1.0Latest
New~795Updated Jun 26, 2026

.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 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
Files1
1 files · 1.0 KB

Select a file to preview

Overall Score

88/100

Grade

A

Excellent

Safety

95

Quality

88

Clarity

85

Completeness

78

Summary

This skill guides AI agents to review .NET/C# code and ensure it meets best practices across architecture, design patterns, dependency injection, testing, and security. It covers documentation, async patterns, error handling, configuration, and AI/Semantic Kernel integration for a complete .NET development workflow.

Detected Capabilities

code analysiscode reviewdocumentation validationpattern matchingbest practices evaluation

Trigger Keywords

Phrases that MCP clients use to match this skill to user intent.

dotnet best practicescsharp code reviewdotnet architecture reviewsemantic kernel integrationmstest validation

Use Cases

  • Review C# code for architectural compliance with established patterns
  • Validate dependency injection configuration and service registration
  • Ensure comprehensive XML documentation and code comments
  • Check async/await patterns and resource management practices
  • Verify testing standards compliance using MSTest and FluentAssertions
  • Validate AI/Semantic Kernel integration patterns and configuration
  • Review configuration and settings implementation with strong typing
  • Ensure error handling and structured logging practices

Quality Notes

  • Comprehensive coverage of modern .NET/C# best practices including C# 12+ and .NET 8
  • Well-organized sections with clear headers and logical flow
  • Specific implementation guidance (e.g., primary constructor syntax, CommandHandler pattern)
  • References modern Microsoft frameworks (SemanticKernel, Extensions.DependencyInjection)
  • Covers full development lifecycle: architecture, testing, security, performance
  • Includes domain-specific guidance for AI/ML operations with SemanticKernel
  • Practical examples provided (e.g., resource manager access pattern)
  • Good balance of design principles (SOLID) and concrete implementation patterns
  • Addresses localization and resource management alongside code quality
  • Read-only analysis skill with no destructive operations or external dependencies
Model: claude-haiku-4-5-20251001Analyzed: Jun 26, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Use github/dotnet-best-practices in your dev environment

Command Palette

Search for a command to run...