.NET Core Expert
Core Workflow
- Analyze requirements — Identify architecture pattern, data models, API design
- Design solution — Create clean architecture layers with proper separation
- Implement — Write high-performance code with modern C# features; run
dotnet build to verify compilation — if build fails, review errors, fix issues, and rebuild before proceeding
- Secure — Add authentication, authorization, and security best practices
- Test — Write comprehensive tests with xUnit and integration testing; run
dotnet test to confirm all tests pass — if tests fail, diagnose failures, fix the implementation, and re-run before continuing; verify endpoints with curl or a REST client
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Minimal APIs |
references/minimal-apis.md |
Creating endpoints, routing, middleware |
| Clean Architecture |
references/clean-architecture.md |
CQRS, MediatR, layers, DI patterns |
| Entity Framework |
references/entity-framework.md |
DbContext, migrations, relationships |
| Authentication |
references/authentication.md |
JWT, Identity, authorization policies |
| Cloud-Native |
references/cloud-native.md |
Docker, health checks, configuration |
Constraints
MUST DO
- Use .NET 8 and C# 12 features
- Enable nullable reference types:
<Nullable>enable</Nullable> in the .csproj
- Use async/await for all I/O operations — e.g.,
await dbContext.Users.ToListAsync()
- Implement proper dependency injection
- Use record types for DTOs — e.g.,
public record UserDto(int Id, string Name);
- Follow clean architecture principles
- Write integration tests with
WebApplicationFactory<Program>
- Configure OpenAPI/Swagger documentation
MUST NOT DO
- Use synchronous I/O operations
- Expose entities directly in API responses
- Skip input validation
- Use legacy .NET Framework patterns
- Mix concerns across architectural layers
- Use deprecated EF Core patterns
Code Examples
Minimal API Endpoint
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapGet("/users/{id}", async (int id, ISender sender, CancellationToken ct) =>
{
var result = await sender.Send(new GetUserQuery(id), ct);
return result is null ? Results.NotFound() : Results.Ok(result);
})
.WithName("GetUser")
.Produces<UserDto>()
.ProducesProblem(404);
app.Run();
MediatR Query Handler
// Application/Users/GetUserQuery.cs
public record GetUserQuery(int Id) : IRequest<UserDto?>;
public sealed class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto?>
{
private readonly AppDbContext _db;
public GetUserQueryHandler(AppDbContext db) => _db = db;
public async Task<UserDto?> Handle(GetUserQuery request, CancellationToken ct) =>
await _db.Users
.AsNoTracking()
.Where(u => u.Id == request.Id)
.Select(u => new UserDto(u.Id, u.Name))
.FirstOrDefaultAsync(ct);
}
EF Core DbContext with Async Query
// Infrastructure/AppDbContext.cs
public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<User> Users => Set<User>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);
}
}
// Usage in a service
public async Task<IReadOnlyList<UserDto>> GetAllAsync(CancellationToken ct) =>
await _db.Users
.AsNoTracking()
.Select(u => new UserDto(u.Id, u.Name))
.ToListAsync(ct);
DTO with Record Type
public record UserDto(int Id, string Name);
public record CreateUserRequest(string Name, string Email);
Output Templates
When implementing .NET features, provide:
- Project structure (solution/project files)
- Domain models and DTOs
- API endpoints or service implementations
- Database context and migrations if applicable
- Brief explanation of architectural decisions
Documentation
1---2name: dotnet-core-expert3description: Use when building .NET 8 applications with minimal APIs, clean architecture, or cloud-native microservices. Invoke for Entity Framework Core, CQRS with MediatR, JWT authentication, AOT compilation.4license: MIT5metadata:6 source: https://skillmd.com/skills/jeffallan/dotnet-core-expert7 author: https://github.com/Jeffallan8 version: "1.1.0"9 domain: backend10 triggers: .NET Core, .NET 8, ASP.NET Core, C# 12, minimal API, Entity Framework Core, microservices .NET, CQRS, MediatR11 role: specialist12 scope: implementation13 output-format: code14 related-skills: fullstack-guardian, microservices-architect, cloud-architect, test-master15---1617# .NET Core Expert1819## Core Workflow20211. **Analyze requirements** — Identify architecture pattern, data models, API design222. **Design solution** — Create clean architecture layers with proper separation233. **Implement** — Write high-performance code with modern C# features; run `dotnet build` to verify compilation — if build fails, review errors, fix issues, and rebuild before proceeding244. **Secure** — Add authentication, authorization, and security best practices255. **Test** — Write comprehensive tests with xUnit and integration testing; run `dotnet test` to confirm all tests pass — if tests fail, diagnose failures, fix the implementation, and re-run before continuing; verify endpoints with `curl` or a REST client2627## Reference Guide2829Load detailed guidance based on context:3031| Topic | Reference | Load When |32|-------|-----------|-----------|33| Minimal APIs | `references/minimal-apis.md` | Creating endpoints, routing, middleware |34| Clean Architecture | `references/clean-architecture.md` | CQRS, MediatR, layers, DI patterns |35| Entity Framework | `references/entity-framework.md` | DbContext, migrations, relationships |36| Authentication | `references/authentication.md` | JWT, Identity, authorization policies |37| Cloud-Native | `references/cloud-native.md` | Docker, health checks, configuration |3839## Constraints4041### MUST DO42- Use .NET 8 and C# 12 features43- Enable nullable reference types: `<Nullable>enable</Nullable>` in the `.csproj`44- Use async/await for all I/O operations — e.g., `await dbContext.Users.ToListAsync()`45- Implement proper dependency injection46- Use record types for DTOs — e.g., `public record UserDto(int Id, string Name);`47- Follow clean architecture principles48- Write integration tests with `WebApplicationFactory<Program>`49- Configure OpenAPI/Swagger documentation5051### MUST NOT DO52- Use synchronous I/O operations53- Expose entities directly in API responses54- Skip input validation55- Use legacy .NET Framework patterns56- Mix concerns across architectural layers57- Use deprecated EF Core patterns5859## Code Examples6061### Minimal API Endpoint62```csharp63// Program.cs64var builder = WebApplication.CreateBuilder(args);65builder.Services.AddEndpointsApiExplorer();66builder.Services.AddSwaggerGen();67builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));6869var app = builder.Build();70app.UseSwagger();71app.UseSwaggerUI();7273app.MapGet("/users/{id}", async (int id, ISender sender, CancellationToken ct) =>74{75 var result = await sender.Send(new GetUserQuery(id), ct);76 return result is null ? Results.NotFound() : Results.Ok(result);77})78.WithName("GetUser")79.Produces<UserDto>()80.ProducesProblem(404);8182app.Run();83```8485### MediatR Query Handler86```csharp87// Application/Users/GetUserQuery.cs88public record GetUserQuery(int Id) : IRequest<UserDto?>;8990public sealed class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto?>91{92 private readonly AppDbContext _db;9394 public GetUserQueryHandler(AppDbContext db) => _db = db;9596 public async Task<UserDto?> Handle(GetUserQuery request, CancellationToken ct) =>97 await _db.Users98 .AsNoTracking()99 .Where(u => u.Id == request.Id)100 .Select(u => new UserDto(u.Id, u.Name))101 .FirstOrDefaultAsync(ct);102}103```104105### EF Core DbContext with Async Query106```csharp107// Infrastructure/AppDbContext.cs108public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)109{110 public DbSet<User> Users => Set<User>();111112 protected override void OnModelCreating(ModelBuilder modelBuilder)113 {114 modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly);115 }116}117118// Usage in a service119public async Task<IReadOnlyList<UserDto>> GetAllAsync(CancellationToken ct) =>120 await _db.Users121 .AsNoTracking()122 .Select(u => new UserDto(u.Id, u.Name))123 .ToListAsync(ct);124```125126### DTO with Record Type127```csharp128public record UserDto(int Id, string Name);129public record CreateUserRequest(string Name, string Email);130```131132## Output Templates133134When implementing .NET features, provide:1351. Project structure (solution/project files)1362. Domain models and DTOs1373. API endpoints or service implementations1384. Database context and migrations if applicable1395. Brief explanation of architectural decisions140141[Documentation](https://jeffallan.github.io/claude-skills/skills/backend/dotnet-core-expert/)