Dotnet Best Practices

Dotnet Best Practices

Makes the AI bring .NET/C# code up to a project's best practices: XML docs, dependency injection, async patterns, resources and MSTest testing standards.

Skill files1 file
SKILL.md86 lines
1
---
2
name: dotnet-best-practices
3
description: 'Ensure .NET/C# code meets best practices for the solution/project.'
4
---
5
6
# .NET/C# Best Practices
7
8
Your task is to ensure .NET/C# code in ${selection} meets the best practices specific to this solution/project. This includes:
9
10
## Documentation & Structure
11
12
- Create comprehensive XML documentation comments for all public classes, interfaces, methods, and properties
13
- Include parameter descriptions and return value descriptions in XML comments
14
- Follow the established namespace structure: {Core|Console|App|Service}.{Feature}
15
16
## Design Patterns & Architecture
17
18
- Use primary constructor syntax for dependency injection (e.g., `public class MyClass(IDependency dependency)`)
19
- Implement the Command Handler pattern with generic base classes (e.g., `CommandHandler<TOptions>`)
20
- Use interface segregation with clear naming conventions (prefix interfaces with 'I')
21
- Follow the Factory pattern for complex object creation.
22
23
## Dependency Injection & Services
24
25
- Use constructor dependency injection with null checks via ArgumentNullException
26
- Register services with appropriate lifetimes (Singleton, Scoped, Transient)
27
- Use Microsoft.Extensions.DependencyInjection patterns
28
- Implement service interfaces for testability
29
30
## Resource Management & Localization
31
32
- Use ResourceManager for localized messages and error strings
33
- Separate LogMessages and ErrorMessages resource files
34
- Access resources via `_resourceManager.GetString("MessageKey")`
35
36
## Async/Await Patterns
37
38
- Use async/await for all I/O operations and long-running tasks
39
- Return Task or Task<T> from async methods
40
- Use ConfigureAwait(false) where appropriate
41
- Handle async exceptions properly
42
43
## Testing Standards
44
45
- Use MSTest framework with FluentAssertions for assertions
46
- Follow AAA pattern (Arrange, Act, Assert)
47
- Use Moq for mocking dependencies
48
- Test both success and failure scenarios
49
- Include null parameter validation tests
50
51
## Configuration & Settings
52
53
- Use strongly-typed configuration classes with data annotations
54
- Implement validation attributes (Required, NotEmptyOrWhitespace)
55
- Use IConfiguration binding for settings
56
- Support appsettings.json configuration files
57
58
## Semantic Kernel & AI Integration
59
60
- Use Microsoft.SemanticKernel for AI operations
61
- Implement proper kernel configuration and service registration
62
- Handle AI model settings (ChatCompletion, Embedding, etc.)
63
- Use structured output patterns for reliable AI responses
64
65
## Error Handling & Logging
66
67
- Use structured logging with Microsoft.Extensions.Logging
68
- Include scoped logging with meaningful context
69
- Throw specific exceptions with descriptive messages
70
- Use try-catch blocks for expected failure scenarios
71
72
## Performance & Security
73
74
- Use C# 12+ features and .NET 8 optimizations where applicable
75
- Implement proper input validation and sanitization
76
- Use parameterized queries for database operations
77
- Follow secure coding practices for AI/ML operations
78
79
## Code Quality
80
81
- Ensure SOLID principles compliance
82
- Avoid code duplication through base classes and utilities
83
- Use meaningful names that reflect domain concepts
84
- Keep methods focused and cohesive
85
- Implement proper disposal patterns for resources
86

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…