Documentation
¶
Overview ¶
Package query contains types and components for implementing Domain Queries and Query Handlers for producing Domain Read Models, which should compose the Read API of your application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Answer ¶
type Answer interface{}
Answer is a marker interface for answers to Domain Queries, returned by a Query Handler.
type Dispatcher ¶
Dispatcher represents a component that routes Domain Queries into their appropriate Query Handlers.
Differently from Command Handlers, Query Handlers return an Answer to the Domain Query dispatched, which usually is the Domain Read Model for a specific query type.
Implementations can be synchronous or asynchronous, although it is generally used as a synchronous component, i.e. the call to Dispatch returns when the query has been resolved.
type Handler ¶
Handler is a component capable of handling Domain Queries, resolving them into an Answer, typically a Domain Read Model.
An Handler implementation specifies their supported Query type using the QueryType method. Please, make sure the type returned by this method reflects the same type of the Query submitted in your application.
type SimpleBus ¶
type SimpleBus struct {
// contains filtered or unexported fields
}
SimpleBus is a simple Query Bus implementation, synchronous and that works in-memory by registering Query Handlers and dispatching Domain Queries, the Bus will take care of routing the Query to the appropriate Query Handler.
Use NewSimpleBus to create a new SimpleBus instance.
func NewSimpleBus ¶
func NewSimpleBus() *SimpleBus
NewSimpleBus returns a new instance of SimpleBus.
func (SimpleBus) Dispatch ¶
Dispatch routes the provided Domain Query to the appropriate Query Handler registered in the Bus, if any, and returns the produced Answer.
If the submitted Query has not been registered by any Handler, an error will be returned instead.
func (*SimpleBus) Register ¶
Register adds the specified Query Handler to the SimpleBus routing table, associated with the Query Handler's Domain Query type, so that calls to Dispatch using the specified Domain Query type will be routed to this Query Handler.
Please note, when registering multiple Handlers accepting the same Query type, the last registration call will overwrite any previous Handler registration, as SimpleBus, intentionally, does not support any kind of voting mechanism.