toDomainEvent

fun <T : Any> T.toDomainEvent(aggregateId: AggregateId, commandId: String, id: String = generateGlobalId(), version: Int = Version.INITIAL_VERSION, ownerId: String = OwnerId.DEFAULT_OWNER_ID, sequence: Int = DEFAULT_EVENT_SEQUENCE, isLast: Boolean = true, header: Header = DefaultHeader.empty(), createTime: Long = System.currentTimeMillis()): DomainEvent<T>

Converts an object to a domain event with full parameter control.

This extension function creates a DomainEvent from any object, allowing complete customization of all event properties. The event metadata is automatically derived from the object's class annotations.

Return

A new DomainEvent instance

Parameters

T

The type of the event body

aggregateId

The aggregate ID this event belongs to

commandId

The ID of the command that triggered this event

id

The unique event ID (default: generated global ID)

version

The aggregate version for this event (default: INITIAL_VERSION)

ownerId

The owner ID of the event (default: DEFAULT_OWNER_ID)

sequence

The sequence number within the event stream (default: DEFAULT_EVENT_SEQUENCE)

isLast

Whether this is the last event in the stream (default: true)

header

The event header containing metadata (default: empty header)

createTime

The timestamp when the event was created (default: current time)

See also


fun <T : Any> T.toDomainEvent(aggregateId: String, tenantId: String, commandId: String, ownerId: String = OwnerId.DEFAULT_OWNER_ID, id: String = generateGlobalId(), version: Int = Version.INITIAL_VERSION, sequence: Int = DEFAULT_EVENT_SEQUENCE, isLast: Boolean = true, header: Header = DefaultHeader.empty(), createTime: Long = System.currentTimeMillis()): DomainEvent<T>

Converts an object to a domain event using string aggregate identifiers.

This extension function creates a DomainEvent from any object, using string identifiers for aggregate ID and tenant. The named aggregate information is derived from the object's class annotations.

Return

A new DomainEvent instance

Parameters

T

The type of the event body

aggregateId

The string identifier of the aggregate

tenantId

The tenant identifier

commandId

The ID of the command that triggered this event

ownerId

The owner ID of the event (default: DEFAULT_OWNER_ID)

id

The unique event ID (default: generated global ID)

version

The aggregate version for this event (default: INITIAL_VERSION)

sequence

The sequence number within the event stream (default: DEFAULT_EVENT_SEQUENCE)

isLast

Whether this is the last event in the stream (default: true)

header

The event header containing metadata (default: empty header)

createTime

The timestamp when the event was created (default: current time)

See also

NamedAggregate

Throws

if the event type doesn't have a named aggregate getter