application.cqrs.metadata¶
src.application.cqrs.metadata
¶
CQRS Metadata Types.
Dataclasses and enums for CQRS registry metadata. These types define the structure of command and query registry entries.
Design Principles: - Immutable (frozen=True) - registry entries never change at runtime - Type-safe (kw_only=True) - explicit field assignment - Self-documenting - clear field names and docstrings
Reference
- docs/architecture/registry.md (Registry Pattern Architecture)
- docs/architecture/cqrs-registry.md (CQRS-specific documentation)
Classes¶
CQRSCategory
¶
Bases: str, Enum
Categories for CQRS commands and queries.
Categories match the domain boundaries and help organize commands/queries by their functional area.
Source code in src/application/cqrs/metadata.py
CachePolicy
¶
Bases: str, Enum
Cache policies for query results.
Hints for container/infrastructure on how to cache query results.
Source code in src/application/cqrs/metadata.py
CommandMetadata
dataclass
¶
Metadata for a command in the CQRS registry.
Commands represent user intent to change system state. Each command has a corresponding handler that executes the business logic.
Attributes:
| Name | Type | Description |
|---|---|---|
command_class |
type
|
The command dataclass (e.g., RegisterUser). |
handler_class |
type
|
The handler class (e.g., RegisterUserHandler). |
category |
CQRSCategory
|
Functional category for organization. |
has_result_dto |
bool
|
Whether handler returns a result DTO (vs simple UUID/bool). |
result_dto_class |
type | None
|
The DTO class if has_result_dto is True. |
emits_events |
bool
|
Whether this command publishes domain events. |
requires_transaction |
bool
|
Whether this command needs a database transaction. |
description |
str
|
Human-readable description for documentation. |
Example
CommandMetadata( ... command_class=RegisterUser, ... handler_class=RegisterUserHandler, ... category=CQRSCategory.AUTH, ... emits_events=True, ... requires_transaction=True, ... description="Register new user account with email verification", ... )
Source code in src/application/cqrs/metadata.py
Functions¶
__post_init__
¶
Validate metadata consistency.
Source code in src/application/cqrs/metadata.py
QueryMetadata
dataclass
¶
Metadata for a query in the CQRS registry.
Queries represent requests for data. They never change state and can be safely cached.
Attributes:
| Name | Type | Description |
|---|---|---|
query_class |
type
|
The query dataclass (e.g., GetAccount). |
handler_class |
type
|
The handler class (e.g., GetAccountHandler). |
category |
CQRSCategory
|
Functional category for organization. |
is_paginated |
bool
|
Whether this query supports pagination. |
cache_policy |
CachePolicy
|
Caching hints for infrastructure. |
description |
str
|
Human-readable description for documentation. |
Example
QueryMetadata( ... query_class=ListAccountsByUser, ... handler_class=ListAccountsHandler, ... category=CQRSCategory.DATA_SYNC, ... is_paginated=True, ... cache_policy=CachePolicy.SHORT, ... description="List all accounts for a user across all connections", ... )
Source code in src/application/cqrs/metadata.py
Functions¶
get_handler_factory_name
¶
Compute the expected container factory function name for a handler.
Follows the existing naming convention in container modules: - Commands: get_{snake_case_command}handler - Queries: get_handler
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
CommandMetadata | QueryMetadata
|
Command or query metadata. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Expected factory function name. |
Example
metadata = CommandMetadata( ... command_class=RegisterUser, ... handler_class=RegisterUserHandler, ... category=CQRSCategory.AUTH, ... ) get_handler_factory_name(metadata) 'get_register_user_handler'
Source code in src/application/cqrs/metadata.py
get_handler_dependencies
¶
Extract dependency names from handler init signature.
Used by container auto-wiring to determine what dependencies to inject when creating handler instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler_class
|
type
|
The handler class to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of dependency parameter names from init. |
Example
class RegisterUserHandler: ... def init(self, user_repo, password_service, event_bus): ... pass get_handler_dependencies(RegisterUserHandler) ['user_repo', 'password_service', 'event_bus']