csharp-developer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseC# Developer
C# 开发者
Purpose
用途
Provides expertise in modern C# and .NET development, including ASP.NET Core web applications, Entity Framework Core data access, and enterprise application patterns. Covers C# 12 features and .NET 8 best practices.
提供现代C#和.NET开发相关专业知识,包括ASP.NET Core Web应用、Entity Framework Core数据访问及企业级应用模式。涵盖C# 12特性和.NET 8最佳实践。
When to Use
适用场景
- Building C# applications with .NET 8
- Developing ASP.NET Core web APIs
- Implementing Entity Framework Core data access
- Using modern C# features (records, patterns, etc.)
- Building enterprise .NET applications
- Writing unit tests with xUnit/NUnit
- Implementing dependency injection patterns
- 使用.NET 8构建C#应用
- 开发ASP.NET Core Web API
- 实现Entity Framework Core数据访问
- 使用现代C#特性(记录、模式匹配等)
- 构建企业级.NET应用
- 使用xUnit/NUnit编写单元测试
- 实现依赖注入模式
Quick Start
快速入门
Invoke this skill when:
- Building C# applications with .NET 8
- Developing ASP.NET Core web APIs
- Implementing Entity Framework Core data access
- Using modern C# features
- Building enterprise .NET applications
Do NOT invoke when:
- Building cross-platform .NET MAUI apps (use dotnet-core-expert)
- Working with .NET Framework 4.8 (use dotnet-framework-4.8-expert)
- Building Windows desktop apps (use windows-app-developer)
- Azure-specific infrastructure (use azure-infra-engineer)
在以下场景调用此技能:
- 使用.NET 8构建C#应用
- 开发ASP.NET Core Web API
- 实现Entity Framework Core数据访问
- 使用现代C#特性
- 构建企业级.NET应用
请勿在以下场景调用:
- 构建跨平台.NET MAUI应用(请使用dotnet-core-expert)
- 处理.NET Framework 4.8相关工作(请使用dotnet-framework-4.8-expert)
- 构建Windows桌面应用(请使用windows-app-developer)
- 处理Azure特定基础设施(请使用azure-infra-engineer)
Decision Framework
决策框架
Project Type:
├── Web API → ASP.NET Core Minimal API or Controllers
├── Web App → Blazor or Razor Pages
├── Background service → Worker Service
├── Desktop → WPF, WinUI, or MAUI
└── Library → .NET Standard or .NET 8
Data Access:
├── SQL with ORM → Entity Framework Core
├── SQL with control → Dapper
├── NoSQL → MongoDB driver or Cosmos SDK
└── Multiple DBs → Repository patternProject Type:
├── Web API → ASP.NET Core Minimal API or Controllers
├── Web App → Blazor or Razor Pages
├── Background service → Worker Service
├── Desktop → WPF, WinUI, or MAUI
└── Library → .NET Standard or .NET 8
Data Access:
├── SQL with ORM → Entity Framework Core
├── SQL with control → Dapper
├── NoSQL → MongoDB driver or Cosmos SDK
└── Multiple DBs → Repository patternCore Workflows
核心工作流程
1. ASP.NET Core API Development
1. ASP.NET Core API开发
- Create project with appropriate template
- Configure dependency injection
- Implement domain models
- Set up EF Core with migrations
- Create controllers or minimal API endpoints
- Add validation and error handling
- Implement authentication/authorization
- Add OpenAPI documentation
- 使用合适的模板创建项目
- 配置依赖注入
- 实现领域模型
- 配置EF Core及迁移
- 创建控制器或极简API端点
- 添加验证和错误处理
- 实现身份验证/授权
- 添加OpenAPI文档
2. Entity Framework Core Setup
2. Entity Framework Core配置
- Define entity models
- Configure DbContext
- Set up relationships and constraints
- Create initial migration
- Implement repository pattern if needed
- Add query optimization
- Configure connection resilience
- 定义实体模型
- 配置DbContext
- 设置关系和约束
- 创建初始迁移
- 按需实现仓储模式
- 添加查询优化
- 配置连接弹性
3. Testing Strategy
3. 测试策略
- Set up xUnit or NUnit project
- Create unit tests with mocks
- Implement integration tests
- Use WebApplicationFactory for API tests
- Add test database fixtures
- Configure CI test pipeline
- 搭建xUnit或NUnit项目
- 使用模拟对象创建单元测试
- 实现集成测试
- 使用WebApplicationFactory进行API测试
- 添加测试数据库夹具
- 配置CI测试流水线
Best Practices
最佳实践
- Use records for DTOs and immutable data
- Leverage pattern matching for cleaner code
- Use nullable reference types
- Implement IAsyncDisposable for async cleanup
- Use primary constructors in C# 12
- Configure EF Core query splitting for includes
- 使用记录类型处理DTO和不可变数据
- 利用模式匹配编写更简洁的代码
- 使用可为空引用类型
- 实现IAsyncDisposable进行异步清理
- 在C# 12中使用主构造函数
- 为EF Core的Include操作配置查询拆分
Anti-Patterns
反模式
| Anti-Pattern | Problem | Correct Approach |
|---|---|---|
| Service locator | Hidden dependencies | Constructor injection |
| Async void | Unhandled exceptions | async Task everywhere |
| N+1 queries | Performance issues | Use Include() or projection |
| Throwing from constructors | Hard to handle | Use factory methods |
| String-based config | Runtime errors | Strongly-typed options |
| 反模式 | 问题 | 正确做法 |
|---|---|---|
| Service locator | 依赖关系隐藏 | 构造函数注入 |
| Async void | 未处理异常 | 全局使用async Task |
| N+1 queries | 性能问题 | 使用Include()或投影 |
| 从构造函数抛出异常 | 难以处理 | 使用工厂方法 |
| 基于字符串的配置 | 运行时错误 | 强类型选项 |