Skip to content

Event Handler

The Readmodel interface in comby defines the contract for managing queryable representations of domain state. It combines two key responsibilities: event handling and state restoration, enabling the read model to remain up-to-date and consistent with the event-sourced domain.r validating the command and emitting events as a result of the command being executed.

In comby an EventHandler is defined as an interface as follows:

go
type DomainEventHandler struct {
	DomainEvtPath        string
	DomainEvtName        string
	DomainEvt            DomainEvt
	DomainEvtHandlerFunc DomainEventHandlerFunc
}

type EventHandler interface {
	Identifier

	// GetDomainEventHandlers retrieves the list of all events handlers for a given domain event.
	GetDomainEventHandlers(domainEvt DomainEvt) []*DomainEventHandler

	// GetDomainEvents returns a list of all supported domain events.
	GetDomainEvents() []DomainEvt
}

The GetDomainEventHandlers method retrieves a list of event handlers (DomainEventHandler) for a specific domain event (DomainEvt). This dynamic retrieval enables the framework to process domain events by invoking the appropriate handlers, ensuring that events are managed according to their type and context.

The GetDomainEvents method returns a list of all domain events that the event handler supports. This provides a clear overview of the event types the event handler is designed to process, facilitating event routing and system introspection.

By implementing the EventHandler interface, developers can create modular and reusable event-handling components, ensuring that domain events are consistently and efficiently managed within the comby framework.