
Dotnet Best Practices
Audit or refactor selected .NET/C# code so XML docs, DI, patterns, and localization match your solution’s conventions.
Overview
dotnet-best-practices is an agent skill most often used in Build (also Ship) that ensures selected .NET/C# code follows solution-specific documentation, DI, patterns, and localization rules.
Install
npx skills add https://github.com/github/awesome-copilot --skill dotnet-best-practicesWhat is this skill?
- Requires XML documentation on all public types and members with parameter and return descriptions
- Enforces primary-constructor DI, ArgumentNullException guards, and I-prefixed interface segregation
- Standardizes CommandHandler<TOptions> and Factory patterns for commands and complex creation
- Separates LogMessages and ErrorMessages resource files accessed via ResourceManager keys
- Aligns namespaces to {Core|Console|App|Service}.{Feature} per solution layout
Adoption & trust: 12k installs on skills.sh; 34.6k GitHub stars; 3/3 security scanners passed (skills.sh audits).
Who is it for?
Indie builders maintaining a structured .NET solution who want the agent to enforce the same DI, handler, and localization patterns the team already uses.
Skip if: Greenfield experiments with no established namespace or handler conventions, or non-.NET stacks where C# rules do not apply.
When should I use this skill?
Ensure .NET/C# code in a selection meets best practices specific to the solution or project.
What do I get? / Deliverables
Selected project code is brought in line with XML docs, architecture patterns, service registration, and ResourceManager usage so it is review-ready and consistent with the rest of the solution.
- Refactored or annotated C# matching XML doc, DI, and pattern rules
- Aligned ResourceManager keys for log and error strings where applicable
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Canonical shelf is Build because the skill governs how C# services, handlers, and DI are written; it is invoked while implementing backend features. Backend is the primary fit: namespaces, CommandHandler bases, Microsoft.Extensions.DependencyInjection, and ResourceManager strings are server-side concerns.
Where it fits
After scaffolding a new command handler, run the skill on the selection so primary constructors, I-prefixed interfaces, and XML docs match existing handlers.
Before opening a PR, apply the skill to touched public APIs to verify namespace segments and localized ErrorMessages keys.
When patching a production hotfix in a service project, keep DI lifetimes and ArgumentNullException guards consistent with the rest of the codebase.
How it compares
Use as a project-shaped review skill instead of generic C# style snippets that ignore CommandHandler bases and resource file layout.
Common Questions / FAQ
Who is dotnet-best-practices for?
Solo and small-team builders on .NET who want Copilot or similar agents to align refactors and new code with their solution’s documented patterns for DI, handlers, and localization.
When should I use dotnet-best-practices?
During Build when implementing or extending backend features in a selection, and during Ship review before merging public API or service changes; also when onboarding an agent to your existing Core/Service namespace layout.
Is dotnet-best-practices safe to install?
It is guidance for code structure and does not inherently run shell or network actions from the skill text; review the Security Audits panel on this Prism page and inspect the skill package in your repo before trusting it in CI.
SKILL.md
READMESKILL.md - Dotnet Best Practices
# .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