Claude CodeでUnit of Workパターンを設計する:複数リポジトリのトランザクション統一・変更追跡・原子コミット

はじめに 「複数のリポジトリを使う処理でトランザクションが統一されていなかった」——Unit of Workパターンで複数リポジトリへの変更を1つのトランザクションにまとめ、原子的にコミット/ロールバックする設計をClaude Codeに生成させる。 CLAUDE.mdにUnit of Work設計ルールを書く ## Unit of Workパターン設計ルール ### 役割 - 1つのユース...

By · · 1 min read
Claude CodeでUnit of Workパターンを設計する:複数リポジトリのトランザクション統一・変更追跡・原子コミット

Source: DEV Community

はじめに 「複数のリポジトリを使う処理でトランザクションが統一されていなかった」——Unit of Workパターンで複数リポジトリへの変更を1つのトランザクションにまとめ、原子的にコミット/ロールバックする設計をClaude Codeに生成させる。 CLAUDE.mdにUnit of Work設計ルールを書く ## Unit of Workパターン設計ルール ### 役割 - 1つのユースケース(トランザクション)スコープを管理 - スコープ内で取得した集約を追跡(変更検出) - commit()で全変更を一括保存、rollback()で全変更を取り消し ### リポジトリとの関係 - リポジトリはUoWが管理するDBコネクション/Prismaトランザクションを使用 - UoWを通じてリポジトリを取得する(UoW.getOrderRepository()) - UoW外でリポジトリを直接使用しない ### Prismaとの統合 - Prisma.$transaction(async (tx) => { ... }) をUoWのスコープとして使用 - リポジトリはPrismaトランザクション(tx)を受け取る Unit of Work実装の生成 Unit of Workパターンを設計してください。 要件: - Prismaトランザクションとの統合 - リポジトリアクセスのファクトリー - ドメインイベントの収集とコミット後の発行 - エラー時の自動ロールバック 生成ファイル: src/infrastructure/unitOfWork/ 生成されるUnit of Work実装 // src/infrastructure/unitOfWork/unitOfWork.ts — Unit of Work export interface IUnitOfWork { orderRepository: IOrderRepository; userRepository: IUserRepository; inventoryRepository: IInventoryRepository; commit(): Promise<void>; rollback(): Promise<void>; } export class PrismaUnitOfWo

Related Posts

Similar Topics

#ai (19)#fix (17)#feat (17)#javascript (14)#webdev (14)#chore (9)#opensource (8)#large language models (4)#modernization (6)#es6 (6)#css (6)#backbonejs (6)#redis (2)#programming (5)#nextjs (5)#security (5)#code generation (4)#api (4)#html (4)#node (4)

Trending on ShareHub

  1. Understanding Modern JavaScript Frameworks in 2026
    by Alex Chen · Feb 12, 2026 · 0 likes
  2. The System Design Primer
    by Sarah Kim · Feb 12, 2026 · 0 likes
  3. Just shipped my first open-source project!
    by Alex Chen · Feb 12, 2026 · 0 likes
  4. OpenAI Blog
    by Sarah Kim · Feb 12, 2026 · 0 likes
  5. Building Accessible Web Applications: A Practical Guide
    by Alex Chen · Feb 12, 2026 · 0 likes
  6. Rapper Lil Poppa dead at 25, days after releasing new music
    Rapper Lil Poppa dead at 25, days after releasing new music
    by Anonymous User · Feb 19, 2026 · 0 likes
  7. write-for-us
    by Volt Raven · Mar 7, 2026 · 0 likes
  8. Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    Before the Coffee Gets Cold: Heartfelt Story of Time Travel and Second Chances
    by Anonymous User · Feb 12, 2026 · 0 likes
    #coffee gets cold #the #time travel
  9. Best DoorDash Promo Code Reddit Finds for Top Discounts
    Best DoorDash Promo Code Reddit Finds for Top Discounts
    by Anonymous User · Feb 12, 2026 · 0 likes
    #doordash #promo #reddit
  10. Premium SEO Services That Boost Rankings & Revenue | VirtualSEO.Expert
    by Anonymous User · Feb 12, 2026 · 0 likes
  11. NBC under fire for commentary about Team USA women's hockey team
    NBC under fire for commentary about Team USA women's hockey team
    by Anonymous User · Feb 18, 2026 · 0 likes
  12. Where to Watch The Nanny: Streaming and Online Viewing Options
    Where to Watch The Nanny: Streaming and Online Viewing Options
    by Anonymous User · Feb 12, 2026 · 0 likes
    #streaming #the nanny #where
  13. How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    How Much Is Kindle Unlimited? Subscription Cost and Plan Details
    by Anonymous User · Feb 12, 2026 · 0 likes
    #kindle unlimited #subscription #unlimited
  14. Russian skater facing backlash for comment about Amber Glenn
    Russian skater facing backlash for comment about Amber Glenn
    by Anonymous User · Feb 18, 2026 · 0 likes
  15. Google News
    Google News
    by Anonymous User · Feb 18, 2026 · 0 likes

Latest on ShareHub

Browse Topics

#artificial intelligence (31560)#data science (24017)#ai (16831)#generative ai (15034)#crypto (14996)#machine learning (14680)#bitcoin (14238)#featured (13557)#news & insights (13064)#crypto news (11082)

Around the Network