mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 21:46:31 +00:00
18 lines
1.2 KiB
Plaintext
18 lines
1.2 KiB
Plaintext
---
|
|
description: ".NET/C# coding conventions: naming, async patterns, DI, EF Core, error handling, layered architecture"
|
|
globs: ["**/*.cs", "**/*.csproj", "**/*.sln"]
|
|
---
|
|
# .NET / C#
|
|
|
|
- PascalCase for classes, methods, properties, namespaces; camelCase for locals and parameters; prefix interfaces with `I`
|
|
- Use `async`/`await` for I/O-bound operations, do not suffix async methods with Async
|
|
- Use dependency injection via constructor injection; register services in `Program.cs`
|
|
- Use linq2db for small projects, EF Core with migrations for big ones; avoid raw SQL unless performance-critical; prevent N+1 with `.Include()` or projection
|
|
- Use `Result<T, E>` pattern or custom error types over throwing exceptions for expected failures
|
|
- Use `var` when type is obvious; prefer LINQ/lambdas for collections
|
|
- Use C# 10+ features: records for DTOs, pattern matching, null-coalescing
|
|
- Layer structure: Controllers -> Services (interfaces) -> Repositories -> Data/EF contexts
|
|
- Use Data Annotations or FluentValidation for input validation
|
|
- Use middleware for cross-cutting: auth, error handling, logging
|
|
- API versioning via URL or header; document with XML comments for Swagger/OpenAPI
|