Command¶
Module defining the Command base class for domain commands.
command
¶
Module defining the Command base class for domain commands.
Command
¶
Bases: Message[RawCommandType]
Base class for all domain commands.
Commands represent an intent to do something in the domain.
They are requests that may succeed or fail, and are handled by a command handler.
Commands are named in imperative mood (e.g., CreateOrder, RegisterCustomer,
ProcessPayment).
Example
class CreateOrder(Command):
def __init__(
self, customer_id: str, items: list, metadata: MessageMetadata | None = None
):
super().__init__(metadata)
self._customer_id = customer_id
self._items = items
@property
def _payload(self) -> dict[str, Any]:
return {"customer_id": self._customer_id, "items": self._items}