View on GitHub
Clean Architecture Toolkit for .NET
Clean Architecture Toolkit is a clean, modular architecture foundation for .NET applications.
It embraces SOLID principles and focuses on maintainability, testability, and scalability through clear boundaries and pluggable design.

|   HOME   |   MODULE OVERVIEW   |   DEMO   |

Plans for Cat.EFCore

New projects in the existing Cat.EFCore module: base query and command handlers for Entity Framework Core, and a transaction decorator for commands.
Status: not started. Cat.EFCore itself exists. Only the new projects are planned. This plan collects what we know. The open questions need an answer before the build.

Contents

The idea

Two jobs repeat in every service that uses Entity Framework Core.

Handlers. In the infrastructure project, every query handler and command handler repeats the same work: get the DbContext, read or change entities, save, return an ICatResponse. A base class can do the repeating part, so a handler only holds what is special about it.

Transactions. Some work must succeed or fail as one unit. A command decorator can open a transaction before the handler runs, commit when the response is a success, and roll back when it fails. The handler does not have to know.

Neither gets a module of its own. They become new projects inside Cat.EFCore, next to the entity and model builder projects. A developer picks the projects they need and leaves the rest.

What we already know

From the root readme:

From the existing modules:

From the demo:

From the saga plan:

Decisions and open questions

Decided

Topic Decision
Scope Base handlers for queries and commands on EF Core, and a transaction decorator for commands.
Home One module, Cat.EFCore, with several projects. Handlers and transactions are new projects next to Cat.EFCore.Entities and Cat.EFCore.Extensions. A developer picks what they want to use.
No separate transactions module There is no Cat.Transactions. Transactions are part of Cat.EFCore.
Entities The entity base classes stay in Cat.EFCore.Entities.
Dependencies The core never references this module. Only the infrastructure does.
Demo case Saving an order and its lines in one go.

Open

Structure

Handlers

Transactions

Questions before building

  1. Which projects do we add to Cat.EFCore, and what do we call them?
  2. What do you like better for the handlers: a base class to inherit, or a few helper methods to call?
  3. Should a command handler save changes, or does something else, like the transaction decorator, do it?
  4. Which database errors should become standard responses?
  5. Must it work with database first services and scaffolded contexts?
  6. Which paging, sorting and filtering do we need, and do we want it here or in Cat.Queries?
  7. Do we handle optimistic concurrency from the start?
  8. Should the unit of a transaction be a command, a service request or a workflow?
  9. Should a failed response always roll back?
  10. Do we mark commands that need a transaction, or give all of them one?
  11. Is an outbox part of the first version, and does it live here or in Cat.Messaging?
  12. How should Cat.Dapper and EF Core share a transaction?
  13. Do you want the place order workflow to become one transaction in the demo, or is the cancel on failure approach fine?
  14. What isolation level do you want as the default?
  15. Is SQL Server the only database to test against? Temporal tables already tie the demo to it.
  16. How much of the demo handler code should move into the module? Do we start by refactoring the demo handlers, as the Aspire plan does for the API client?