بنقرة واحدة
handler
Handler 業務邏輯層實作技能,協助開發者實作符合專案規範的 Handler,包含業務邏輯處理、流程協調、Result Pattern 錯誤處理與跨 Repository 操作。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Handler 業務邏輯層實作技能,協助開發者實作符合專案規範的 Handler,包含業務邏輯處理、流程協調、Result Pattern 錯誤處理與跨 Repository 操作。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
API 開發流程引導技能,協助開發者選擇合適的開發流程(API First 或 Code First),並提供 OpenAPI 規格管理、程式碼產生等自動化支援。
BDD 測試實作技能,協助開發者使用 Reqnroll 撰寫行為驅動開發測試,包含 Gherkin 語法、測試步驟實作與 Docker 測試環境設定。
快取策略與多層快取設計技能,協助開發者實作 L1 Memory + L2 Redis 分層快取,包含 TTL 管理、版本控制與失效策略。
EF Core 操作與最佳化技能,協助開發者正確使用 Entity Framework Core,包含 DbContextFactory 模式、查詢最佳化、Migration 管理與反向工程。
專案初始化與配置技能,負責引導使用者完成新專案的初始化、配置設定、GitHub 範本套用與專案狀態檢測。
Repository 設計指導技能,協助開發者根據業務需求選擇最合適的 Repository 設計策略(資料表導向 vs 需求導向 vs 混合模式)。
استنادا إلى تصنيف SOC المهني
| name | handler |
| description | Handler 業務邏輯層實作技能,協助開發者實作符合專案規範的 Handler,包含業務邏輯處理、流程協調、Result Pattern 錯誤處理與跨 Repository 操作。 |
本 SKILL 須搭配閱讀:開發規則
Handler 業務邏輯層實作技能,協助開發者實作符合專案規範的 Handler,包含業務邏輯處理、流程協調、Result Pattern 錯誤處理等。
Handler 是純業務邏輯層,不受「API First vs Code First」選擇影響:
因此本 SKILL 未區分 API 開發流程,所有 Handler 實作指導均適用於兩種方式。
👉 API 開發流程選擇 → 參考 /api-development SKILL
Result<TSuccess, TFailure> 作為回傳類型@workspace 我需要實作 Handler 業務邏輯
使用 handler 實作業務邏輯
graph LR
A[Controller] --> B[Handler]
B --> C[Repository 1]
B --> D[Repository 2]
B --> E[External Service]
C --> F[(Database)]
D --> F
業務邏輯
錯誤處理
交易管理
HTTP 相關邏輯
直接資料存取
拋出業務例外
完整實作範本請參考生產代碼(透過 FileResolver):
node .claude/skills/shared/FileResolver.js get-content \
JobBank1111.Job.WebAPI/Member/MemberHandler.cs
public async Task<Result<MemberResponse, Failure>> CreateMemberAsync(
CreateMemberRequest request,
CancellationToken cancellationToken = default)
{
try
{
// 業務邏輯
var member = new Member
{
Email = request.Email,
Name = request.Name
};
var createResult = await repository.CreateAsync(member, cancellationToken);
return createResult.Match(
success => Result.Success<MemberResponse, Failure>(MapToResponse(success)),
failure => Result.Failure<MemberResponse, Failure>(failure)
);
}
catch (Exception ex)
{
return Result.Failure<MemberResponse, Failure>(new Failure
{
Code = nameof(FailureCode.InternalServerError),
Message = ex.Message,
TraceId = traceContext.TraceId,
Exception = ex // 保存原始例外
});
}
}
public async Task<Result<OrderDetail, Failure>> CreateOrderAsync(
CreateOrderRequest request,
CancellationToken cancellationToken = default)
{
await using var dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
try
{
// 1. 建立訂單
var orderResult = await orderRepository.CreateAsync(...);
if (orderResult.IsFailure) return orderResult;
// 2. 建立訂單明細
var itemsResult = await orderItemRepository.CreateBatchAsync(...);
if (itemsResult.IsFailure)
{
await transaction.RollbackAsync(cancellationToken);
return Result.Failure<OrderDetail, Failure>(itemsResult.Error);
}
// 3. 更新庫存
var stockResult = await inventoryRepository.ReduceStockAsync(...);
if (stockResult.IsFailure)
{
await transaction.RollbackAsync(cancellationToken);
return Result.Failure<OrderDetail, Failure>(stockResult.Error);
}
await transaction.CommitAsync(cancellationToken);
return Result.Success<OrderDetail, Failure>(...);
}
catch (Exception ex)
{
await transaction.RollbackAsync(cancellationToken);
return Result.Failure<OrderDetail, Failure>(new Failure { ... });
}
}
node .claude/skills/shared/FileResolver.js get-content JobBank1111.Job.WebAPI/Member/MemberHandler.cs// ❌ 錯誤
await repository.CreateAsync(member);
// ✅ 正確
await repository.CreateAsync(member, cancellationToken);
// ❌ 錯誤
if (await repository.EmailExistsAsync(email))
throw new BusinessException("Email 已存在");
// ✅ 正確
if (await repository.EmailExistsAsync(email, cancellationToken))
return Result.Failure<MemberResponse, Failure>(new Failure
{
Code = nameof(FailureCode.DuplicateEmail),
Message = "Email 已被註冊",
TraceId = traceContext.TraceId
});
// ❌ 錯誤
catch (Exception ex)
{
return Result.Failure<T, Failure>(new Failure
{
Code = nameof(FailureCode.InternalServerError),
Message = ex.Message
// 缺少 Exception = ex
});
}
// ✅ 正確
catch (Exception ex)
{
return Result.Failure<T, Failure>(new Failure
{
Code = nameof(FailureCode.InternalServerError),
Message = ex.Message,
TraceId = traceContext.TraceId,
Exception = ex // 保存原始例外
});
}
repository-design - Repository 設計與實作error-handling - Result Pattern 與錯誤處理api-development - Controller 整合feature-development-agent - 使用本 skill 的完整功能開發流程