Skip to content

Commit

Permalink
Add naming conventions sections in CQRS
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojciech Klusek committed Jan 5, 2024
1 parent e782400 commit 7702896
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/cqrs/command/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ As you can see, the command handler is really simple - it just finds project wit
6. Do not throw exceptions from inside commands. The client will receive generic error (`500 Internal Server Error`). Do it only as a last resort.
7. Database transaction will be commited at the end of the [pipeline] (assuming [CommitTransaction] pipeline element was added), so it's not recommended to commit it inside query handler as it may make serialized [events] inconsistent with the entity.

## Naming conventions

Commands in CQRS are responsible for modifying the state of the system, and therefore their names should reflect the action they trigger. A common convention is to use imperative verbs that clearly describe the intent, such as `UpdateProjectName`, `DeleteProject`, or `AssignEmployeeToAssignment`. Handlers should share the identical name as the associated contract, appended with the `CH` suffix. This practice enhances ease of identification and ensures a straightforward correlation between contracts and their corresponding handlers.

[aggregates]: ../../domain/aggregate/index.md
[events]: ../../domain/domain_event/index.md
[pipeline]: ../pipeline/index.md
Expand Down
4 changes: 4 additions & 0 deletions docs/cqrs/operation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ public class PayForAccessOH : IOperationHandler<PayForAccess, PaymentTokenDTO>
}
}
```

## Naming conventions

Operations are designed to both modify the state of the system and provide a result. To uphold a consistent naming convention, these operations should be named to reflect both their transformative action and if possible the nature of the information returned. Striking a balance between clarity and conciseness, names like `GenerateReferralLink`, `GetNextQuestion`, or `AnswerQuestion` convey both the intent of state modification and the potential for a consequential result. Correspondingly, handlers for operations should start with the name of the associated operation while incorporating the `OH` suffix.
4 changes: 4 additions & 0 deletions docs/cqrs/query/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ public class ProjectsQH : IQueryHandler<Projects, List<ProjectDTO>>
}
```

## Naming conventions

Queries are designed to retrieve information without altering the system's state. To maintain a clear and consistent naming convention, queries should possess names that directly indicate the type of information being requested. An effective approach is to use descriptive nouns or noun phrases, exemplified by names like `Projects`, `ProjectById`, or `EmployeesInAssignment`. Query handlers should be named in alignment with the associated query, appending the `QH` suffix.

[validation]: ../validation/index.md

0 comments on commit 7702896

Please sign in to comment.