Agent skill · software engineering · affaan-m
dotnet-patterns
惯用的C#和.NET模式、约定、依赖注入、async/await以及构建健壮、可维护的.NET应用程序的最佳实践。
Why this skill is useful
Provides specific C# and .NET patterns and best practices that enhance the AI's ability to generate robust and maintainable applications.
What it needs
About 3k tokens when loaded. Last updated 2026-08-06. 238,342 stars on the source repository.
What this skill does
.NET 开发模式 用于构建健壮、高性能且可维护应用程序的惯用 C# 和 .NET 模式。 何时激活 编写新的 C# 代码时 审查 C# 代码时 重构现有 .NET 应用程序时 使用 ASP.NET Core 设计服务架构时 核心原则 1. 优先使用不可变性 对数据模型使用记录和仅初始化属性。可变性应作为明确且有理由的选择。 2. 显式优于隐式 明确表达可空性、访问修饰符和意图。 3. 依赖抽象 对服务边界使用接口。通过依赖注入容器注册。 异步/等待模式 正确使用异步 并行异步操作 选项模式 将配置节绑定到强类型对象。 结果模式 对预期失败返回显式成功/失败,而非抛出异常。 使用 EF Core 的仓储模式 中间件与管道 最小 API 模式 守卫子句 应避免的反模式 反模式 修复方案 --- --- async void 方法 返回 Task(事件处理程序除外) .Result 或 .Wait() 使用 await catch (Exception) { } 处理或带上下文重新抛出 构造函数中的 new Service() 使用构造函数注入 public 字段 使用带适当访问器的属性 业务逻辑中的 dynamic 使用泛型或显式类型 可变的 static 状态 使用依赖注入作用域或 ConcurrentDictionary 循环中的 string.Format 使用 StringBuilder 或内插字符串处理程序
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills affaan-m/dotnet-patterns--92367b