unit-of-work

Coordinate a single SaveChanges commit per HTTP request across controllers, services, and repositories.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/RushuiGuan/claude --skill unit-of-work-rushuiguan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-of-work
Source: https://github.com/RushuiGuan/claude/tree/main/skills/unit-of-work
Command: npx skills add https://github.com/RushuiGuan/claude --skill unit-of-work-rushuiguan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Coordinate a single per-request commit across controllers, services, and repositories by applying the Unit of Work pattern.

Core Features & Use Cases

  • One-commit boundary per HTTP request: The controller defines the transaction boundary; services perform domain logic; repositories are not responsible for committing.
  • Clear separation of concerns: Services return entities and the controller maps them to DTOs for the client.
  • Integrated error handling: SaveAndReturn translates common persistence issues into appropriate HTTP status codes (NotFound, NameConflict, etc.).

Quick Start

Refactor a controller action to validate input, delegate to a service for business logic, and commit the transaction with a single SaveAndReturn call.

Frequently Asked Questions about unit-of-work

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce a single SaveChanges call per HTTP request in EF Core?

To enforce a single SaveChanges per HTTP request, apply the Unit of Work pattern by having the controller define the transaction boundary and call SaveAndReturn, while services handle business logic and repositories manage data access without committing.

What is the best way to separate business logic from transaction commits in an ASP.NET Core controller?

The best way to separate transaction commits from business logic is using the Unit of Work pattern: services execute domain logic and return entities, while the controller validates input, maps entities to DTOs, and performs a single SaveAndReturn to commit.

How does SaveAndReturn handle persistence errors in an ASP.NET Core Web API?

SaveAndReturn handles persistence errors by translating common EF Core database issues into appropriate HTTP status codes, such as NotFound or NameConflict, directly within the controller transaction boundary.

When do I need the Unit of Work pattern for my ASP.NET Core endpoints?

You need the Unit of Work pattern for ASP.NET Core endpoints that modify data (POST, PUT, DELETE) and require a coordinated single commit across multiple repositories and services, ensuring data consistency within a single HTTP request.

Can I use EF Core repositories without having them call SaveChanges directly?

Yes, you can use EF Core repositories without direct SaveChanges calls by delegating the commit responsibility to the controller via the Unit of Work pattern, where a single SaveAndReturn action handles the transaction boundary for the entire request.

Why should controllers map entities to DTOs instead of services in an ASP.NET Core application?

Controllers should map entities to DTOs to maintain a clear separation of concerns: services focus on domain logic and return entities to the controller, which then translates them into DTOs to return to the client after the transaction commit.