Dispatch
The core of the command dispatcher.
Attention
You do not have to add this middleware yourself, the Builder will add
it for you.
Usage
The dispatch middleware actually handles the dispatching of requests to their handlers. It should be the last middleware in the chain.
Registration
You do not have to add this middleware yourself, the Builder will add
it for you.
Instead you setup the middleware using with_locator() and
with_factory() to provide its dependencies.
Context
We add a Dispatch context instance for each handler executed. It will
contain the result of the function call and the name of the handler.
result = message[banshee.Dispatch].result
name = message[banshee.Dispatch].name
Reference
- class banshee.Dispatch(name, result)
Bases:
objectDispatch context.
Marks a message as having had its request processed by a specific handler and contains the result of that execution.
- name: str
handler name
- class banshee.DispatchMiddleware(locator, factory)
Bases:
MiddlewareDispatch middleware.
Implements the command dispatcher design pattern to route requests to their configured handlers.
Uses the pre-configured
HandlerLocatorto retrieve a all associatedHandlerReferenceinstances, before passing the references one by one to aHandlerFactoryin order to get andHandlerinstance to call.A
Dispatchcontext will be added to the message for each successful handler.- Parameters:
locator (HandlerLocator) – locator to lookup associated handlers for a message
factory (HandlerFactory) – factory to instantiate a concrete handler from a reference
- async __call__(message, handle)
Handle message.
Dispatch the request to all associated handlers and store the results.
- Parameters:
message (Message[T]) – message to process
handle (HandleMessage) – next middleware invoker
- Returns:
processed message
- Raises:
banshee.errors.DispatchError – when one or more handlers fails
- Return type:
Message[T]