技能 dotnet-backend-patterns
B

dotnet-backend-patterns

安全 ⚙️ 外部命令🌐 網路存取📁 檔案系統存取

建構生產級 .NET 後端

開發 .NET 後端需要了解非同步模式、依賴注入和資料庫存取策略。本技能提供經過驗證的範本和最佳實踐,用於建構可維護、可測試且高效能的 API。

支援: Claude Codex Code(CC)
🥉 73 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「dotnet-backend-patterns」。 Generate a product service with Result pattern and caching

預期結果:

  • Result<T> 模式搭配 Success/Failure 靜態方法
  • ICacheService相依性用於快取側旁模式
  • FluentValidation 整合用於請求驗證
  • ILogger 注入搭配適當的日誌層級
  • 所有非同步方法中的 CancellationToken 傳遞
  • 使用儲存庫模式的軟刪除支援

正在使用「dotnet-backend-patterns」。 Create a user repository using Dapper with parameterized queries

預期結果:

  • 透過工廠模式注入 IDbConnection
  • 使用 @Id、@SearchTerm 預留位置進行參數化 SQL
  • QueryFirstOrDefaultAsync 用於單一記錄
  • QueryAsync 用於搭配 DynamicParameters 的多個結果
  • 用於多重陳述式作業的交易支援

正在使用「dotnet-backend-patterns」。 Set up dependency injection for a payment service

預期結果:

  • 用於付款處理服務的 Scoped 生命週期
  • IOptions<PaymentOptions> 設定繫結
  • 透過 IHttpClientFactory 註冊 HttpClient
  • 用於 Redis 的單例 ConnectionMultiplexer
  • 用於多重付款提供者的索引鍵服務

安全審計

安全
v4 • 1/17/2026

This is a pure documentation and code template skill containing only educational C#/.NET patterns. Static findings are 100% false positives caused by the scanner misidentifying: (1) markdown code fences as Ruby backticks, (2) SQL/database patterns as cryptographic terms, (3) standard C# namespace imports as reconnaissance. No executable code, network calls, file system access, or command execution exists. All content is static educational material.

6
已掃描檔案
2,791
分析行數
3
發現項
4
審計總數

風險因素

⚙️ 外部命令 (85)
references/dapper-patterns.md:32-59 references/dapper-patterns.md:59-63 references/dapper-patterns.md:63-85 references/dapper-patterns.md:85-91 references/dapper-patterns.md:91-133 references/dapper-patterns.md:133-137 references/dapper-patterns.md:137-177 references/dapper-patterns.md:177-181 references/dapper-patterns.md:181-246 references/dapper-patterns.md:246-250 references/dapper-patterns.md:250-278 references/dapper-patterns.md:278-284 references/dapper-patterns.md:284-308 references/dapper-patterns.md:308-312 references/dapper-patterns.md:312-348 references/dapper-patterns.md:348-352 references/dapper-patterns.md:352-397 references/dapper-patterns.md:397-401 references/dapper-patterns.md:401-429 references/dapper-patterns.md:429-435 references/dapper-patterns.md:435-443 references/dapper-patterns.md:443-447 references/dapper-patterns.md:447-458 references/dapper-patterns.md:458-462 references/dapper-patterns.md:462-468 references/dapper-patterns.md:468-474 references/dapper-patterns.md:474-517 references/dapper-patterns.md:517-521 references/dapper-patterns.md:521-544 references/ef-core-best-practices.md:9-20 references/ef-core-best-practices.md:20-24 references/ef-core-best-practices.md:24-41 references/ef-core-best-practices.md:41-45 references/ef-core-best-practices.md:45-64 references/ef-core-best-practices.md:64-68 references/ef-core-best-practices.md:68-78 references/ef-core-best-practices.md:78-82 references/ef-core-best-practices.md:82-100 references/ef-core-best-practices.md:100-106 references/ef-core-best-practices.md:106-130 references/ef-core-best-practices.md:130-134 references/ef-core-best-practices.md:134-147 references/ef-core-best-practices.md:147-153 references/ef-core-best-practices.md:153-176 references/ef-core-best-practices.md:176-180 references/ef-core-best-practices.md:180-188 references/ef-core-best-practices.md:188-194 references/ef-core-best-practices.md:194-228 references/ef-core-best-practices.md:228-232 references/ef-core-best-practices.md:232-253 references/ef-core-best-practices.md:253-259 references/ef-core-best-practices.md:259-280 references/ef-core-best-practices.md:280-286 references/ef-core-best-practices.md:286-295 references/ef-core-best-practices.md:295-299 references/ef-core-best-practices.md:299-315 references/ef-core-best-practices.md:315-319 references/ef-core-best-practices.md:319-329 references/ef-core-best-practices.md:329-333 references/ef-core-best-practices.md:333-355 SKILL.md:25-47 SKILL.md:47-51 SKILL.md:51-101 SKILL.md:101-105 SKILL.md:105-150 SKILL.md:150-154 SKILL.md:154-227 SKILL.md:227-231 SKILL.md:231-293 SKILL.md:293-299 SKILL.md:299-374 SKILL.md:374-378 SKILL.md:378-478 SKILL.md:478-484 SKILL.md:484-597 SKILL.md:597-603 SKILL.md:603-708 SKILL.md:708-712 SKILL.md:712-772 SKILL.md:772-789 SKILL.md:789 SKILL.md:789-794 SKILL.md:794-796 SKILL.md:796-802 SKILL.md:802-803
🌐 網路存取 (1)
📁 檔案系統存取 (5)
審計者: claude 查看審計歷史 →

品質評分

55
架構
100
可維護性
87
內容
22
社群
100
安全
83
規範符合性

你能建構什麼

API 開發

使用 Minimal API 端點設計和實作 RESTful API,並包含適當的錯誤處理和驗證

資料存取層

使用 EF Core 為複雜領域或 Dapper 為效能關鍵查詢建立儲存庫層

測試策略

使用模擬依賴項和針對測試資料庫的整合測試撰寫全面的測試套件

試試這些提示

建立服務
為 [EntityName] 建立具有 CRUD 操作的服務實作,使用 Result 模式、依賴注入和驗證。包含快取側旁模式和適當的錯誤處理。
新增儲存庫
為 [EntityName] 產生 [Dapper/EF Core] 儲存庫,包含搜尋、分頁和大量作業的非同步方法。包含參數化查詢和適當的連線處理。
設定 DI
為 [ServiceName] 撰寫服務註冊,使用適當的生命週期(scoped/singleton/transient)、IOptions 設定,以及必要的索引鍵服務。
撰寫測試
使用 Moq 為 [ServiceName] 撰寫 xUnit 測試。包含快樂路徑、驗證失敗和錯誤場景。使用 Fact 和 Theory 屬性搭配適當的斷言。

最佳實務

  • 全程使用 async/await,並始終將 CancellationToken 傳遞給非同步方法
  • 對於業務邏輯失敗,優先使用 Result<T> 而非異常,並在 API 邊界驗證輸入
  • 對於唯讀查詢使用 AsNoTracking(),且僅選取需要的欄位以減少記憶體使用量

避免

  • 絕對不要使用 .Result 或 .GetAwaiter().GetResult() 封鎖非同步程式碼,因為這會導致死結
  • 避免直接在 API 回應中暴露 EF 實體 - 使用 DTO 進行資料轉換
  • 不要使用字串串接來建構 SQL 查詢 - 務必使用參數化查詢以防止注入

常見問題

支援哪些 .NET 版本?
範本支援 .NET 8+ 並使用 C# 12 功能,如主要建構函式和集合運算式。
最大回應大小是多少?
回應大小取決於查詢。使用分頁搭配可設定的頁面大小(預設 50,最大 200)。
我可以與 Minimal APIs 搭配使用嗎?
可以。所有服務模式都能與使用依賴注入的控制器型 API 和 Minimal API 端點搭配使用。
我的資料安全嗎?
本技能僅產生程式碼範本,不會存取檔案、資料庫或外部傳輸任何資料。
為什麼我的查詢很慢?
對讀取使用 AsNoTracking(),僅選取需要的欄位,為篩選欄位新增資料庫索引,並考慮對熱門路徑使用 Dapper。
這與其他技能相比如何?
本技能提供 C#/.NET 特定的模式。對於與語言無關的 REST 原則,請使用一般 API 設計技能。