Domain events are the primary mechanism by which one part of your domain communicates a meaningful state change to the rest of the system — without creating direct coupling. All events in HexCore are immutable Pydantic models (frozen=True) stamped with a UUID and a UTC timestamp on construction. Three concrete subclasses cover the standard entity lifecycle, and theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Indroic/HexCore/llms.txt
Use this file to discover all available pages before exploring further.
EventBus abstract class defines the port your infrastructure must implement for publishing and subscribing.
DomainEvent
Fields
Unique identifier for this specific event instance. Auto-generated.
UTC timestamp of when the event occurred, set automatically via
datetime.now(UTC).Computed property
event_name
"Event" suffix and converted to uppercase.
The class name with
"Event" removed, uppercased. For example, UserCreatedEvent → "USERCREATED".event_name is a Pydantic computed_field, so it is included in .model_dump() and serialised in JSON output automatically.Generic Entity Lifecycle Events
HexCore provides three generic event types that cover the standard CRUD lifecycle of any entity.EntityCreatedEvent[T]
entity_data so downstream handlers do not need to re-query the database.
The
id of the entity that was created.The full entity instance.
T must be bound to BaseEntity.EntityUpdatedEvent[T]
The
id of the entity that was updated.The entity instance reflecting the new state after the update.
EntityDeletedEvent
The
id of the entity that was deleted.EventHandler type alias
DomainEvent argument and returns nothing. Use this type when annotating subscriber functions passed to EventBus.subscribe().
EventBus
InMemoryEventBus, a Redis-backed bus) must implement this interface.
Methods
subscribe
The event class to subscribe to (e.g.,
UserCreatedEvent).An async callable matching
Callable[[DomainEvent], Awaitable[None]].publish
The domain event instance to publish.
Deprecated aliases
register (deprecated)
subscribe(). Emits a DeprecationWarning at runtime.
dispatch (deprecated)
publish(). Emits a DeprecationWarning at runtime.
IEventDispatcher alias
EventBus. Code that imports IEventDispatcher continues to work without changes, but new code should use EventBus directly.