application

package
v1.0.0-beta.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SimpleUnitOfWork

type SimpleUnitOfWork struct {
	// contains filtered or unexported fields
}

SimpleUnitOfWork is the default implementation of UnitOfWork. It provides atomic event persistence across multiple entities with optimistic concurrency control.

func NewSimpleUnitOfWork

func NewSimpleUnitOfWork(eventStore domain.EventStore, dispatcher *domain.EventDispatcher) *SimpleUnitOfWork

NewSimpleUnitOfWork creates a new SimpleUnitOfWork instance. eventStore is required for persisting events. dispatcher is optional and can be nil if event dispatch is not needed.

func (*SimpleUnitOfWork) Commit

func (uow *SimpleUnitOfWork) Commit(ctx context.Context) error

Commit persists all uncommitted events from all tracked entities atomically.

func (*SimpleUnitOfWork) Rollback

func (uow *SimpleUnitOfWork) Rollback() error

Rollback clears the tracking of entities without clearing their uncommitted events.

func (*SimpleUnitOfWork) Track

func (uow *SimpleUnitOfWork) Track(entities ...domain.Entity) error

Track registers one or more entities to be included in the unit of work.

type UnitOfWork

type UnitOfWork interface {
	// Track registers one or more entities to be included in the unit of work.
	// The expected version for optimistic concurrency is computed by subtracting
	// uncommitted events from the current sequence number, so Track works correctly
	// regardless of whether RecordEvent was called before or after Track.
	// If any entity is invalid or already tracked, an error is returned and no entities are tracked.
	Track(entities ...domain.Entity) error

	// Commit persists all uncommitted events from all tracked entities atomically.
	// If any entity fails to persist, the entire commit fails and rollback occurs.
	// After successful persistence, events are optionally dispatched via EventDispatcher.
	Commit(ctx context.Context) error

	// Rollback clears the tracking of entities without clearing their uncommitted events.
	// This allows entities to be retried in a new unit of work.
	Rollback() error
}

UnitOfWork is an interface for managing transactions across multiple entities. It provides atomic persistence of uncommitted events from tracked entities.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址