$npx -y skills add Jeffallan/claude-skills --skill dotnet-core-expertUse 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.
| 1 | # .NET Core Expert |
| 2 | |
| 3 | ## Core Workflow |
| 4 | |
| 5 | 1. **Analyze requirements** — Identify architecture pattern, data models, API design |
| 6 | 2. **Design solution** — Create clean architecture layers with proper separation |
| 7 | 3. **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 |
| 8 | 4. **Secure** — Add authentication, authorization, and security best practices |
| 9 | 5. **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 |
| 10 | |
| 11 | ## Reference Guide |
| 12 | |
| 13 | Load detailed guidance based on context: |
| 14 | |
| 15 | | Topic | Reference | Load When | |
| 16 | |-------|-----------|-----------| |
| 17 | | Minimal APIs | `references/minimal-apis.md` | Creating endpoints, routing, middleware | |
| 18 | | Clean Architecture | `references/clean-architecture.md` | CQRS, MediatR, layers, DI patterns | |
| 19 | | Entity Framework | `references/entity-framework.md` | DbContext, migrations, relationships | |
| 20 | | Authentication | `references/authentication.md` | JWT, Identity, authorization policies | |
| 21 | | Cloud-Native | `references/cloud-native.md` | Docker, health checks, configuration | |
| 22 | |
| 23 | ## Constraints |
| 24 | |
| 25 | ### MUST DO |
| 26 | - Use .NET 8 and C# 12 features |
| 27 | - Enable nullable reference types: `<Nullable>enable</Nullable>` in the `.csproj` |
| 28 | - Use async/await for all I/O operations — e.g., `await dbContext.Users.ToListAsync()` |
| 29 | - Implement proper dependency injection |
| 30 | - Use record types for DTOs — e.g., `public record UserDto(int Id, string Name);` |
| 31 | - Follow clean architecture principles |
| 32 | - Write integration tests with `WebApplicationFactory<Program>` |
| 33 | - Configure OpenAPI/Swagger documentation |
| 34 | |
| 35 | ### MUST NOT DO |
| 36 | - Use synchronous I/O operations |
| 37 | - Expose entities directly in API responses |
| 38 | - Skip input validation |
| 39 | - Use legacy .NET Framework patterns |
| 40 | - Mix concerns across architectural layers |
| 41 | - Use deprecated EF Core patterns |
| 42 | |
| 43 | ## Code Examples |
| 44 | |
| 45 | ### Minimal API Endpoint |
| 46 | ```csharp |
| 47 | // Program.cs |
| 48 | var builder = WebApplication.CreateBuilder(args); |
| 49 | builder.Services.AddEndpointsApiExplorer(); |
| 50 | builder.Services.AddSwaggerGen(); |
| 51 | builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly)); |
| 52 | |
| 53 | var app = builder.Build(); |
| 54 | app.UseSwagger(); |
| 55 | app.UseSwaggerUI(); |
| 56 | |
| 57 | app.MapGet("/users/{id}", async (int id, ISender sender, CancellationToken ct) => |
| 58 | { |
| 59 | var result = await sender.Send(new GetUserQuery(id), ct); |
| 60 | return result is null ? Results.NotFound() : Results.Ok(result); |
| 61 | }) |
| 62 | .WithName("GetUser") |
| 63 | .Produces<UserDto>() |
| 64 | .ProducesProblem(404); |
| 65 | |
| 66 | app.Run(); |
| 67 | ``` |
| 68 | |
| 69 | ### MediatR Query Handler |
| 70 | ```csharp |
| 71 | // Application/Users/GetUserQuery.cs |
| 72 | public record GetUserQuery(int Id) : IRequest<UserDto?>; |
| 73 | |
| 74 | public sealed class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto?> |
| 75 | { |
| 76 | private readonly AppDbContext _db; |
| 77 | |
| 78 | public GetUserQueryHandler(AppDbContext db) => _db = db; |
| 79 | |
| 80 | public async Task<UserDto?> Handle(GetUserQuery request, CancellationToken ct) => |
| 81 | await _db.Users |
| 82 | .AsNoTracking() |
| 83 | .Where(u => u.Id == request.Id) |
| 84 | .Select(u => new UserDto(u.Id, u.Name)) |
| 85 | .FirstOrDefaultAsync(ct); |
| 86 | } |
| 87 | ``` |
| 88 | |
| 89 | ### EF Core DbContext with Async Query |
| 90 | ```csharp |
| 91 | // Infrastructure/AppDbContext.cs |
| 92 | public sealed class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options) |
| 93 | { |
| 94 | public DbSet<User> Users => Set<User>(); |
| 95 | |
| 96 | protected override void OnModelCreating(ModelBuilder modelBuilder) |
| 97 | { |
| 98 | modelBuilder.ApplyConfigurationsFromAssembly(typeof(AppDbContext).Assembly); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // Usage in a service |
| 103 | public async Task<IReadOnlyList<UserDto>> GetAllAsync(CancellationToken ct) => |
| 104 | await _db.Users |
| 105 | .AsNoTracking() |
| 106 | .Select(u => new UserDto(u.Id, u.Name)) |
| 107 | .ToListAsync(ct); |
| 108 | ``` |
| 109 | |
| 110 | ### DTO with Record Type |
| 111 | ```csharp |
| 112 | public record UserDto(int Id, string Name); |
| 113 | public record CreateUserRequest(string Name, string Email); |
| 114 | ``` |
| 115 | |
| 116 | ## Output Templates |
| 117 | |
| 118 | When implementing .NET features, provide: |
| 119 | 1. Project structure (solution/project files) |
| 120 | 2. Domain models and DTOs |
| 121 | 3. API endpoints or service implementations |
| 122 | 4. Database context and migrations if applicable |
| 123 | 5. Brief explanation of architectural decisions |
| 124 | |
| 125 | [Documentation](https://jeffallan |