awesome-copilot/prompts/dotnet-best-practices.prompt.md
Daniel Scott-Raynsford e1c7c7a50e
Add 18 new prompts files (#56)
* Add prompts for .NET best practices, design pattern review, and GitHub Copilot suggestions

- Introduced a comprehensive prompt for ensuring .NET/C# code adheres to best practices, covering documentation, design patterns, dependency injection, resource management, async patterns, testing standards, configuration, AI integration, error handling, performance, security, and code quality.
- Added a prompt for reviewing C#/.NET code for design pattern implementation, providing a checklist for required patterns, architecture, best practices, SOLID principles, performance, maintainability, testability, security, documentation, code clarity, and clean code.
- Created prompts for suggesting relevant GitHub Copilot chatmodes and prompts based on the current repository context, including a structured process for fetching available chatmodes/prompts, scanning local files, and presenting options with rationale.
- Developed a prompt for updating Azure Verified Modules (AVM) in Bicep files, detailing the process for scanning, checking for updates, validating, and handling breaking changes.
- Implemented a prompt for updating implementation plans with new requirements, ensuring machine-readable output and adherence to a strict template.
- Added a prompt for updating the llms.txt file to reflect changes in documentation or specifications, focusing on compliance with the llmstxt specification.
- Created a prompt for updating markdown file indices with files from specified folders, including options for table structures and update strategies.
- Developed a prompt for updating object-oriented component documentation, following industry best practices and ensuring alignment with current implementations.
- Added a prompt for updating specification files, emphasizing clarity, structure, and compliance with established documentation standards.

* CHANGE: Update implementation plan prompt formatting

- Renamed prompt title for clarity.
- Added spacing for improved readability.
- Enhanced structure to ensure compliance with template validation rules.

* CHANGE: Fix typo in .NET best practices prompt

- Corrected "soltion" to "solution" in the prompt description.
2025-07-07 16:17:09 +10:00

3.1 KiB

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

.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