dotnet-design-pattern-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET/C# Design Pattern Review
.NET/C# 设计模式审核
Review the C#/.NET code in ${selection} for design pattern implementation and suggest improvements for the solution/project. Do not make any changes to the code, just provide a review.
审核${selection}中的C#/.NET代码的设计模式实现情况,并为解决方案/项目提出改进建议。请勿修改代码,仅提供审核意见。
Required Design Patterns
要求的设计模式
- Command Pattern: Generic base classes (),
CommandHandler<TOptions>interface,ICommandHandler<TOptions>inheritance, staticCommandHandlerOptionsmethodsSetupCommand(IHost host) - Factory Pattern: Complex object creation service provider integration
- Dependency Injection: Primary constructor syntax, null checks, interface abstractions, proper service lifetimes
ArgumentNullException - Repository Pattern: Async data access interfaces provider abstractions for connections
- Provider Pattern: External service abstractions (database, AI), clear contracts, configuration handling
- Resource Pattern: ResourceManager for localized messages, separate .resx files (LogMessages, ErrorMessages)
- Command Pattern:通用基类()、
CommandHandler<TOptions>接口、ICommandHandler<TOptions>继承、静态CommandHandlerOptions方法SetupCommand(IHost host) - Factory Pattern:复杂对象创建与服务提供程序集成
- Dependency Injection:主构造函数语法、空值检查、接口抽象、合适的服务生命周期
ArgumentNullException - Repository Pattern:异步数据访问接口与连接提供程序抽象
- Provider Pattern:外部服务抽象(数据库、AI)、清晰的契约、配置处理
- Resource Pattern:用于本地化消息的ResourceManager、独立的.resx文件(LogMessages、ErrorMessages)
Review Checklist
审核检查清单
- Design Patterns: Identify patterns used. Are Command Handler, Factory, Provider, and Repository patterns correctly implemented? Missing beneficial patterns?
- Architecture: Follow namespace conventions ()? Proper separation between Core/Console projects? Modular and readable?
{Core|Console|App|Service}.{Feature} - .NET Best Practices: Primary constructors, async/await with Task returns, ResourceManager usage, structured logging, strongly-typed configuration?
- GoF Patterns: Command, Factory, Template Method, Strategy patterns correctly implemented?
- SOLID Principles: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion violations?
- Performance: Proper async/await, resource disposal, ConfigureAwait(false), parallel processing opportunities?
- Maintainability: Clear separation of concerns, consistent error handling, proper configuration usage?
- Testability: Dependencies abstracted via interfaces, mockable components, async testability, AAA pattern compatibility?
- Security: Input validation, secure credential handling, parameterized queries, safe exception handling?
- Documentation: XML docs for public APIs, parameter/return descriptions, resource file organization?
- Code Clarity: Meaningful names reflecting domain concepts, clear intent through patterns, self-explanatory structure?
- Clean Code: Consistent style, appropriate method/class size, minimal complexity, eliminated duplication?
- 设计模式:识别已使用的模式。Command Handler、Factory、Provider和Repository模式是否正确实现?是否遗漏了有益的模式?
- 架构:是否遵循命名空间约定()?Core/Console项目之间是否有适当的分离?是否模块化且可读性强?
{Core|Console|App|Service}.{Feature} - .NET最佳实践:是否使用主构造函数、带Task返回的async/await、ResourceManager、结构化日志、强类型配置?
- GoF模式:Command、Factory、Template Method、Strategy模式是否正确实现?
- SOLID原则:是否存在单一职责、开闭、里氏替换、接口隔离、依赖倒置原则的违反情况?
- 性能:是否正确使用async/await、资源释放、ConfigureAwait(false)?是否有并行处理的机会?
- 可维护性:是否关注点分离清晰、错误处理一致、配置使用得当?
- 可测试性:是否通过接口抽象依赖、组件可模拟、支持异步测试、兼容AAA模式?
- 安全性:是否有输入验证、安全的凭据处理、参数化查询、安全的异常处理?
- 文档:公共API是否有XML文档、参数/返回值说明、资源文件组织是否合理?
- 代码清晰度:命名是否能反映领域概念、通过模式清晰表达意图、结构是否自解释?
- 整洁代码:风格是否一致、方法/类大小是否合适、复杂度是否最低、是否消除了重复代码?
Improvement Focus Areas
改进重点领域
- Command Handlers: Validation in base class, consistent error handling, proper resource management
- Factories: Dependency configuration, service provider integration, disposal patterns
- Providers: Connection management, async patterns, exception handling and logging
- Configuration: Data annotations, validation attributes, secure sensitive value handling
- AI/ML Integration: Semantic Kernel patterns, structured output handling, model configuration
Provide specific, actionable recommendations for improvements aligned with the project's architecture and .NET best practices.
- Command Handlers:基类中的验证、一致的错误处理、适当的资源管理
- Factories:依赖配置、服务提供程序集成、释放模式
- Providers:连接管理、异步模式、异常处理与日志
- 配置:数据注解、验证属性、敏感值的安全处理
- AI/ML集成:Semantic Kernel模式、结构化输出处理、模型配置
请结合项目架构和.NET最佳实践,提供具体、可执行的改进建议。