You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features-application-commands-queries.md
+98-69Lines changed: 98 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,12 @@
8
8
9
9
### Background
10
10
11
-
The [Command Query Separation](https://en.wikipedia.org/wiki/Command%E2%80%93query_separation#:~:text=Command%2Dquery%20separation%20(CQS),the%20caller%2C%20but%20not%20both.) (CQS) principle, introduced by Bertrand Meyer, divides operations into commands, which modify system state and queries, which retrieve data without side effects. This separation enhances code clarity, predictability and maintainability by ensuring methods have distinct roles. By moving away from bloated application services that centralize all logic, commands and queries encapsulate specific business operations in smaller, focused units. This reduces the number of dependencies injected into each handler, improves testability by allowing isolated testing and promotes a cleaner architecture.
11
+
The [Command Query Separation](https://en.wikipedia.org/wiki/Command%E2%80%93query_separation#:~:text=Command%2Dquery%20separation%20(CQS),the%20caller%2C%20but%20not%20both.) (CQS) principle, introduced by Bertrand Meyer, divides operations into commands, which modify system state, and queries, which retrieve data without side effects. This separation enhances code clarity, predictability and maintainability by ensuring methods have distinct roles. By moving away from bloated application services that centralize all logic, commands and queries encapsulate specific business operations in smaller, focused units. This reduces the number of dependencies injected into each handler, improves testability by allowing isolated testing and promotes a cleaner architecture.
12
12
13
-
-**Commands**: Perform state-changing actions (e.g., creating a customer). They typically return `Result<Unit>` for actions with no meaningful return or `Result<T>` for minimal data like an ID.
14
-
-**Queries**: Retrieve data without altering state (e.g., fetching a customer). They return `Result<T>` with the requested data and are idempotent.
13
+
-**Commands**: Perform state-changing actions such as creating or updating data. They typically return `Result<Unit>` for actions with no meaningful return or `Result<T>` for minimal data such as an identifier or summary model.
14
+
-**Queries**: Retrieve data without altering state. They return `Result<T>` with the requested data and are idempotent.
15
15
16
-
In Domain-Driven Design (DDD), commands and queries align with application services, encapsulating business logic and data access. The `Requester` feature in bITDevKit implements CQS using a mediator-like pattern, dispatching requests to handlers with type-safe `Result<T>` outcomes and extensible pipeline behaviors (e.g., validation, retries). This reduces coupling, as callers are unaware of handler implementations, minimizes dependency injection in handlers, and enables consistent handling of cross-cutting concerns, making the codebase more modular and testable.
16
+
In Domain-Driven Design (DDD), commands and queries align with application services, encapsulating business logic and data access. The `Requester` feature in bITDevKit implements CQS using a mediator-like pattern, dispatching requests to handlers with type-safe `Result<T>` outcomes and extensible pipeline behaviors such as validation, retries, and timeouts. This reduces coupling, as callers are unaware of handler implementations, minimizes dependency injection in handlers, and enables consistent handling of cross-cutting concerns, making the codebase more modular and testable.
17
17
18
18
Many handlers also depend on the shared mapping abstraction to translate between request models, domain objects, and response DTOs; see [Common Mapping](./common-mapping.md).
19
19
@@ -28,11 +28,11 @@ Many handlers also depend on the shared mapping abstraction to translate between
28
28
29
29
The `Requester` system provides:
30
30
31
-
-**Requests**: Inherit from `RequestBase<TResponse>`, defining inputs and outputs.
Copy file name to clipboardExpand all lines: docs/features-requester-notifier.md
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1494,20 +1494,20 @@ The `Requester` and `Notifier` systems share similarities with the popular **Med
1494
1494
1495
1495
---
1496
1496
1497
-
# Appendix C: Generic Handlers in Requester and Notifier
1497
+
##Appendix C: Generic Handlers in Requester and Notifier
1498
1498
1499
-
## Overview
1499
+
###Overview
1500
1500
1501
1501
Generic handlers in the `Requester` and `Notifier` systems enable handling of generic request/notification types (e.g., `GenericRequest<TData>`, `GenericNotification<TData>`) with a single handler, reducing code duplication. They are registered using `AddGenericHandlers`, which discovers open generic handlers, validates constraints, and registers closed handlers (e.g., `GenericDataProcessor<UserData>`).
1502
1502
1503
-
## Key Features
1503
+
###Key Features
1504
1504
1505
1505
-**Automatic Discovery**: `AddGenericHandlers` scans assemblies for open generic handlers and discovers type arguments based on constraints.
`AddGenericHandlers` discovers open generic handlers (e.g., `GenericDataProcessor<TData>`), finds type arguments (e.g., `UserData`, `OrderData`) that satisfy constraints, and registers closed handlers.
## Appendix D: Source-Generated Commands and Queries
1605
1607
1606
1608
The source-generated authoring model lets you write a command or query as a single partial type. This is a convenient way to define simple requests without needing separate request and handler classes. The source generator creates the necessary boilerplate code, allowing you to focus on the business logic.
0 commit comments