GitHub Copilot instructions for C# 13 and .NET 9 projects with minimal APIs, EF Core, and clean architecture patterns.
## C# .NET Copilot Custom Instructions
You are a C#/.NET expert for GitHub Copilot. Follow these rules:
### Language Features (C# 13 / .NET 9)
- Use file-scoped namespaces: `namespace MyApp.Services;`
- Use primary constructors for dependency injection
- Use `required` modifier for mandatory properties
- Prefer collection expressions: `[1, 2, 3]` over `new List<int>{1,2,3}`
- Use raw string literals for multi-line strings and JSON
- Use pattern matching with `switch` expressions
### Architecture
- Minimal API style with endpoint grouping via `MapGroup`
- Vertical slice: each feature has its own Request, Handler, Response
- Use `IResult` return types: `Results.Ok()`, `Results.NotFound()`, `Results.BadRequest()`
- Never return entity models from endpoints; always map to DTOs
- Use FluentValidation for request validation
### Entity Framework Core
- Fluent API configuration in separate `IEntityTypeConfiguration<T>` classes
- Use `AsNoTracking()` for read-only queries
- Avoid lazy loading; use explicit `Include()` for related data
- Migrations named: `YYYYMMDD_Description`
- Soft delete with `IsDeleted` flag and global query filter
### Async Patterns
- `async/await` everywhere; never use `.Result` or `.Wait()`
- Use `CancellationToken` on all async methods
- Return `Task<T>` from service methods, not `ValueTask<T>` unless hot path
- Use `IAsyncEnumerable<T>` for streaming large datasets
### Error Handling
- Global exception middleware returning `ProblemDetails`
- Custom exception types: `NotFoundException`, `ValidationException`, `ConflictException`
- Use `Result<T>` pattern for service methods to avoid exceptions for flow control
### Naming
- Interfaces prefixed with `I`: `IUserService`
- Async methods suffixed with `Async`: `GetUserAsync()`
- Private fields: `_camelCase`
- Constants: `PascalCase`
### Testing
- xUnit with `[Fact]` and `[Theory]` attributes
- Use `Moq` or `NSubstitute` for mocking
- Name: `MethodName_Should_ExpectedResult_When_Condition`Free to copy and use. Compatible with GitHub Copilot, GPT-5.
Place in .github/copilot-instructions.md for your .NET repositories. Copilot will follow C# 13 and .NET 9 conventions automatically.
Initial release
Sign in and download this prompt to leave a review.