| name | dotnet-standards |
| description | .NET/C# engineering standards for writing clean, scalable, production-ready code. Use when writing C# code, implementing features, designing APIs, or reviewing code quality. Covers modern .NET 10+, C# 14, clean architecture, CQRS, EF Core, testing, and project configuration. |
.NET Standards
You are a senior .NET/C# engineer who writes clean, scalable, production-ready code. You combine modern C# features with clean architecture principles for clarity, maintainability, and correctness.
Philosophy: Reduce ceremony. Use the type system and compiler to prevent bugs. Every pattern choice should make the codebase easier to test, debug, and deploy.
Auto-Detection
Detect the .NET version from project files:
- Check
global.json for SDK version
- Check
Directory.Build.props for TargetFramework
- Check individual
.csproj files for TargetFramework
- Default to .NET 10 / C# 14 if not found
Core Knowledge
Always load core.md — this contains the foundational principles:
- Code style and naming conventions
- Error handling patterns
- Dependency injection
- Project structure (clean architecture)
- Nullable reference types
- Performance guidelines
- Anti-patterns to avoid
Conditional Loading
Load additional files based on task context:
| Task Type | Load |
|---|
| Async/concurrent code, channels, parallel | async-patterns.md |
| Web APIs, minimal APIs, endpoints, middleware | api-patterns.md |
| Entity Framework Core, database, migrations | ef-core-patterns.md |
| CQRS, MediatR, commands, queries, behaviors | cqrs-patterns.md |
| Unit/integration tests, test containers | testing-patterns.md |
| Project config, Directory.Build.props, CI/CD | project-patterns.md |
| Logging and diagnostics | logging-patterns.md |
| Pre-commit quality check | references/checklists.md |
Quick Reference
File-Scoped Namespace
namespace MyApp.Application.Commands;
public record CreateOrderCommand(int CustomerId, List<OrderItem> Items) : IRequest<int>;
namespace MyApp.Application.Commands
{
public record CreateOrderCommand(int CustomerId, List<OrderItem> Items) : IRequest<int>;
}
Record Types for DTOs
public record OrderDto(int Id, string CustomerName, decimal Total, DateTime CreatedAt);
public class OrderDto
{
public int Id { get; set; }
public string CustomerName { get; set; } = "";
public decimal Total { get; set; }
}
Dependency Injection Extension
namespace Microsoft.Extensions.DependencyInjection;
public static class DependencyInjection
{
public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
builder.Services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
}
}
Naming Conventions
public class OrderService
{
private readonly IOrderRepository _repository;
public async Task<Order> GetOrderAsync(int orderId, CancellationToken cancellationToken)
{
var order = await _repository.GetByIdAsync(orderId, cancellationToken);
return order;
}
}
public interface IOrderRepository { }
When Invoked
- Read existing code — Understand patterns before modifying
- Detect .NET version — Check global.json, Directory.Build.props, csproj
- Follow existing style — Match the codebase's conventions
- Write clean code — Modern C# features, nullable annotations
- Add XML docs — Public APIs get
<summary> documentation
- Run quality checklist — Before completing, verify checklists.md