Naming Conventions
| Element | Convention | Example |
|---|---|---|
| Public types/members | PascalCase | PersonService, GetNameAsync |
| Local variables/parameters | camelCase | personId, resultValue |
| Async methods | Suffix with Async | HandleAsync, GetByIdAsync |
| DTOs | Suffix with DTO | PersonDTO, ToDoDTO |
| Commands | Suffix with Command | CreateToDoCommand |
| Queries | Suffix with Query | GetToDoByIdQuery |
| Handlers | Suffix with Handler | CreateToDoCommandHandler |
| Events | Suffix with Event | ToDoCreatedEvent |
| ID wrappers | readonly record struct | ToDoId, PersonId |
Type Design
- •Use
sealedon classes/records not intended for inheritance. - •Use
readonly record structfor single-value wrappers (e.g.,ToDoId,PersonId). - •Use primary constructors unless complex initialization is required.
- •Use file-scoped namespaces in all C# files.
- •Do not use regions; prefer partial classes if splitting is needed.
Member Ordering
Sort members within a type in this order:
- •Constants
- •Fields
- •Constructors
- •Properties
- •Methods
Within each group, sort alphabetically by name.
Error Handling
- •Use FluentResults
Result<T>andResultinstead of exceptions for expected failures. - •Return
Result.Ok(value)for success,Result.Fail(message)for failures. - •Use
result.IsFailedandresult.IsSuccessfor control flow. - •Reserve exceptions for truly exceptional/unexpected situations.
Imports and Formatting
- •Sort
usingdirectives withSystemfirst. - •Follow
.editorconfig: 2-space indentation, UTF-8, max 120 character lines. - •Assign unused variables to
_to indicate intentional disregard.
Async Patterns
- •Suffix all async methods with
Async. - •Use
CancellationTokenparameters where appropriate. - •Prefer
awaitover.Resultor.Wait().
Dependency Injection
- •Register services in the appropriate project's DI configuration.
- •Use constructor injection via primary constructors.
- •Prefer interfaces for service abstractions.