python_cqrs_dispatcher.dispatcher ================================= .. py:module:: python_cqrs_dispatcher.dispatcher .. autoapi-nested-parse:: CQRS dispatcher integrating CQRS core with mediator pattern. Classes ------- .. autoapisummary:: python_cqrs_dispatcher.dispatcher.CQRSDispatcher Module Contents --------------- .. py:class:: CQRSDispatcher Dispatcher specialized for CQRS pattern. Integrates python-cqrs-core with gridflow-python-mediator, providing: - Type-safe command/query dispatch - Separate command/query handler registration - Pipeline behavior support through mediator Example: >>> dispatcher = CQRSDispatcher() >>> dispatcher.register_command_handler( ... CreateUserCommand, ... CreateUserHandler() ... ) >>> user_id = await dispatcher.send_command(cmd) .. py:method:: register_command_handler(command_type: Type[python_cqrs_core.ICommand], handler: python_cqrs_core.ICommandHandler) -> None Register type-safe command handler. Args: command_type: Command class handler: Command handler instance Raises: ValueError: If handler already registered Example: >>> dispatcher.register_command_handler( ... CreateUserCommand, ... CreateUserHandler() ... ) .. py:method:: register_query_handler(query_type: Type[python_cqrs_core.IQuery], handler: python_cqrs_core.IQueryHandler) -> None Register type-safe query handler. Args: query_type: Query class handler: Query handler instance Raises: ValueError: If handler already registered Example: >>> dispatcher.register_query_handler( ... GetUserQuery, ... GetUserHandler() ... ) .. py:method:: send_command(command: python_cqrs_core.ICommand) -> Any :async: Dispatch command with validation. Args: command: Command to dispatch Returns: Command result Raises: ValueError: If no handler registered Example: >>> cmd = CreateUserCommand(name="John") >>> user_id = await dispatcher.send_command(cmd) .. py:method:: send_query(query: python_cqrs_core.IQuery) -> Any :async: Dispatch query with validation. Args: query: Query to dispatch Returns: Query result Raises: ValueError: If no handler registered Example: >>> query = GetUserQuery(user_id=1) >>> user = await dispatcher.send_query(query) .. py:method:: add_pipeline_behavior(behavior) -> None Add pipeline behavior to mediator. Behaviors execute before all command/query handlers. Args: behavior: Pipeline behavior function Example: >>> from gridflow_python_mediator import LoggingBehavior >>> dispatcher.add_pipeline_behavior( ... LoggingBehavior().handle ... )