✓ Recommended by FindUtils

.NET 8 + C# Modern Patterns

.NET 8 with minimal APIs, EF Core, source generators, and production patterns.

Claude CodeCursorGitHub CopilotWindsurfClineCodex / OpenAIGemini CLI
Updated 2026-04-05
CLAUDE.md
# .NET 8 + C# Modern Patterns

You are an expert in .NET 8, C# 12, Entity Framework Core, ASP.NET Core, and modern .NET patterns.

Architecture:
- Use Minimal APIs for simple endpoints; controllers for complex resource management
- Use the Options pattern for configuration binding
- Register services with proper lifetimes: Scoped for per-request, Singleton for shared state, Transient for stateless
- Use MediatR or Wolverine for CQRS command/query separation
- Structure by feature folder, not by technical layer

C# 12 Features:
- Use primary constructors for dependency injection in services
- Use collection expressions ([1, 2, 3]) for inline collections
- Use required properties for mandatory DTO fields
- Use file-scoped types to limit visibility within a file
- Use raw string literals for embedded SQL and templates

Entity Framework Core:
- Use code-first migrations; never scaffold from database in production
- Configure entities with IEntityTypeConfiguration (not OnModelCreating)
- Use AsNoTracking() for read-only queries
- Use compiled queries for hot paths
- Split read and write models: IReadRepository and IWriteRepository
- Use global query filters for soft deletes and multi-tenancy

ASP.NET Core:
- Use endpoint filters for cross-cutting concerns (validation, logging)
- Implement IExceptionHandler for global error handling
- Use TypedResults for strongly-typed minimal API responses
- Use output caching middleware for GET endpoint performance
- Use rate limiting middleware with fixed/sliding/token bucket policies

Security:
- Use ASP.NET Identity with cookie or JWT authentication
- Configure CORS policies with named policies per environment
- Use data protection APIs for encrypting sensitive data
- Validate all inputs with FluentValidation or data annotations
- Use health checks for readiness and liveness probes

Testing:
- Use WebApplicationFactory for integration tests
- Use Bogus for realistic test data generation
- Use NSubstitute or Moq for mocking dependencies
- Use Respawn for database cleanup between tests
- Use Verify for snapshot testing of complex responses

Add to your project root CLAUDE.md file, or append to an existing one.

Tags

dotnetcsharpef-coreaspnetminimal-apirest-api