mediatpy package
Module contents
- class mediatpy.Mediator(request_handler_factory=None, pipeline_behavior_factory=None, notification_handler_factory=None, raise_error_if_not_any_registered_notification_handler=False)
Bases:
objectClass to register handlers and coordinate their execution in response to arrivals of requests and notifications
All parameters are optional.
my_mediator = Mediator()
- Parameters:
request_handler_factory (
Optional[Callable[[Type[RequestHandler]],Awaitable[RequestHandler]]]) – CustomRequestHandlerfactorypipeline_behavior_factory (
Optional[Callable[[Type[PipelineBehavior]],Awaitable[PipelineBehavior]]]) – CustomPipelineBehaviorfactorynotification_handler_factory (
Optional[Callable[[Type[NotificationHandler]],Awaitable[NotificationHandler]]]) – CustomNotificationHandlerfactoryraise_error_if_not_any_registered_notification_handler (
bool) – Raise an error if noNotificationHandleris found when aNotificationis published
- notification_handler(notification_handler)
Decorator to register a
NotificationHandler- Return type:
None
- pipeline_behavior(pipeline_behavior)
Decorator to register a
PipelineBehavior- Return type:
None
- async publish(notification)
Publish a
Notificationmy_notification = MyNotification() await my_mediator.publish(my_notification)
- Return type:
None
- register_notification_handler(notification_handler)
Manual registration of a
NotificationHandler- Return type:
None
- register_pipeline_behavior(pipeline_behavior)
Manual registration of a
PipelineBehavior- Return type:
None
- register_request_handler(request_handler)
Manual registration of a
RequestHandlermy_mediator.register_request_handler(MyRequestHandler)
- Return type:
None
- request_handler(request_handler)
Decorator to register a
RequestHandler@my_mediator.request_handler class MyRequestHandler(RequestHandler[MyRequest, MyResponse]): async def handle(self, request: MyRequest) -> MyResponse: return MyResponse()
- Return type:
None
- exception mediatpy.NoRequestHandlerFoundError(request)
Bases:
ExceptionError to indicate that a
Requesthas not a registeredRequestHandlerto handle it
- exception mediatpy.NotAnyNotificationHandlerFoundError(notification)
Bases:
ExceptionError to indicate that a
Notificationhas not any registeredNotificationHandlerto handle it
- class mediatpy.Notification
Bases:
objectBase class for any notification
- class mediatpy.NotificationHandler
Bases:
ABC,Generic[TNotification]Base class for any notification handler
- abstractmethod async handle(notification)
- Return type:
None
- class mediatpy.PipelineBehavior
Bases:
ABC,Generic[TRequest,TResponse]Base class for any pipeline behavior
- abstractmethod async handle(request, next_behavior)
Abstract method to handle a request and to return a response
- Parameters:
request (
TypeVar(TRequest, bound=Request)) – Request to be handlednext_behavior (
Callable[...,Awaitable[TypeVar(TResponse)]]) – Next pipeline behavior or request handler to execute
- Return type:
TypeVar(TResponse)
- class mediatpy.Request
Bases:
Generic[TResponse]Base class for any request