Claude-skill-registry backend-csharp-patterns
Use when editing C# backend files (.cs) in src/Backend/, src/Platform/, or src/PlatformExampleApp/. Provides CQRS patterns, repository patterns, validation patterns, entity patterns, background jobs, message bus consumers, data migrations, and fluent helpers for EasyPlatform .NET 9 development.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/backend-csharp-patterns" ~/.claude/skills/majiayu000-claude-skill-registry-backend-csharp-patterns && rm -rf "$T"
manifest:
skills/data/backend-csharp-patterns/SKILL.mdsource content
Backend C# Code Patterns
When implementing backend C# code in EasyPlatform, follow these patterns exactly.
Full Pattern Reference
See the complete code patterns with examples: backend-code-patterns.md
Quick Reference
Pattern Index
| # | Pattern | Key Interface/Contract |
|---|---|---|
| 1 | Clean Architecture | Domain → Application → Persistence → Api layers |
| 2 | Repository | + static expression extensions |
| 3 | Repository API | , , , , |
| 4 | Validation | fluent chain, never throw |
| 5 | Cross-Service | + |
| 6 | Full-Text Search | in query builder |
| 7 | CQRS Command | Command + Result + Handler in ONE file, |
| 8 | Query | + + parallel count/items |
| 9 | Side Effects | Entity Event Handlers in , never in command handlers |
| 10 | Entity | , static expressions, , navigation properties |
| 11 | DTO | , DTO owns mapping, constructor from entity |
| 12 | Fluent Helpers | , , , , |
| 13 | Background Jobs | , |
| 14 | Message Bus | , for deps |
| 15 | Data Migration | , |
| 16 | Multi-Database | / |
Critical Rules
- Repository: Use
- NEVER genericIPlatformQueryableRootRepository<TEntity, TKey>IPlatformRootRepository - Validation: Use
fluent API (PlatformValidationResult
,.And()
) - NEVER.AndAsync()throw ValidationException - Side Effects: Handle in Entity Event Handlers (
) - NEVER in command handlersUseCaseEvents/ - DTO Mapping: DTOs own mapping via
orMapToEntity()
- NEVER map in handlersMapToObject() - Command Structure: Command + Result + Handler in ONE file under
UseCaseCommands/{Feature}/ - Cross-Service: Use RabbitMQ message bus - NEVER direct database access
Anti-Patterns
// ❌ Direct cross-service DB access → ✅ Use message bus // ❌ Custom repository interface → ✅ Use platform repo + extensions // ❌ Manual validation throw → ✅ Use PlatformValidationResult fluent API // ❌ Side effects in handler → ✅ Use entity event handlers // ❌ DTO mapping in handler → ✅ DTO owns mapping via MapToObject()/MapToEntity()
Templates
CQRS Command Template
public sealed class Save{Entity}Command : PlatformCqrsCommand<Save{Entity}CommandResult> { public string Id { get; set; } = ""; public string Name { get; set; } = ""; public override PlatformValidationResult<IPlatformCqrsRequest> Validate() => base.Validate().And(_ => Name.IsNotNullOrEmpty(), "Name required"); } public sealed class Save{Entity}CommandResult : PlatformCqrsCommandResult { public {Entity}Dto Entity { get; set; } = null!; } internal sealed class Save{Entity}CommandHandler : PlatformCqrsCommandApplicationHandler<Save{Entity}Command, Save{Entity}CommandResult> { protected override async Task<Save{Entity}CommandResult> HandleAsync(Save{Entity}Command req, CancellationToken ct) { var entity = req.Id.IsNullOrEmpty() ? req.MapToNewEntity().With(e => e.CreatedBy = RequestContext.UserId()) : await repo.GetByIdAsync(req.Id, ct).Then(e => req.UpdateEntity(e)); await entity.ValidateAsync(repo, ct).EnsureValidAsync(); var saved = await repo.CreateOrUpdateAsync(entity, ct); return new Save{Entity}CommandResult { Entity = new {Entity}Dto(saved) }; } }
Detailed Instructions
For task-specific guidance, also reference:
- backend-dotnet.instructions.md - .NET patterns
- cqrs-patterns.instructions.md - CQRS handlers
- entity-development.instructions.md - Entity design
- validation.instructions.md - Validation patterns
- repository.instructions.md - Repository patterns
- message-bus.instructions.md - Message bus
- background-jobs.instructions.md - Background jobs
- migrations.instructions.md - Data migrations