csharp-developer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

C# 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 pattern
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 pattern

Core Workflows

核心工作流程

1. ASP.NET Core API Development

1. ASP.NET Core API开发

  1. Create project with appropriate template
  2. Configure dependency injection
  3. Implement domain models
  4. Set up EF Core with migrations
  5. Create controllers or minimal API endpoints
  6. Add validation and error handling
  7. Implement authentication/authorization
  8. Add OpenAPI documentation
  1. 使用合适的模板创建项目
  2. 配置依赖注入
  3. 实现领域模型
  4. 配置EF Core及迁移
  5. 创建控制器或极简API端点
  6. 添加验证和错误处理
  7. 实现身份验证/授权
  8. 添加OpenAPI文档

2. Entity Framework Core Setup

2. Entity Framework Core配置

  1. Define entity models
  2. Configure DbContext
  3. Set up relationships and constraints
  4. Create initial migration
  5. Implement repository pattern if needed
  6. Add query optimization
  7. Configure connection resilience
  1. 定义实体模型
  2. 配置DbContext
  3. 设置关系和约束
  4. 创建初始迁移
  5. 按需实现仓储模式
  6. 添加查询优化
  7. 配置连接弹性

3. Testing Strategy

3. 测试策略

  1. Set up xUnit or NUnit project
  2. Create unit tests with mocks
  3. Implement integration tests
  4. Use WebApplicationFactory for API tests
  5. Add test database fixtures
  6. Configure CI test pipeline
  1. 搭建xUnit或NUnit项目
  2. 使用模拟对象创建单元测试
  3. 实现集成测试
  4. 使用WebApplicationFactory进行API测试
  5. 添加测试数据库夹具
  6. 配置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-PatternProblemCorrect Approach
Service locatorHidden dependenciesConstructor injection
Async voidUnhandled exceptionsasync Task everywhere
N+1 queriesPerformance issuesUse Include() or projection
Throwing from constructorsHard to handleUse factory methods
String-based configRuntime errorsStrongly-typed options
反模式问题正确做法
Service locator依赖关系隐藏构造函数注入
Async void未处理异常全局使用async Task
N+1 queries性能问题使用Include()或投影
从构造函数抛出异常难以处理使用工厂方法
基于字符串的配置运行时错误强类型选项