Documentation
¶
Overview ¶
Package aggregate defines interfaces and types necessary to allow users to define their own Aggregate types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRootNotFound = fmt.Errorf("aggregate.Repository: aggregate root not found")
ErrRootNotFound is returned by the Repository when no Events for the specified Aggregate Root have been found.
Functions ¶
func RecordThat ¶
RecordThat records the Domain Event for the specified Aggregate Root.
An error is typically returned if applying the Domain Event on the Aggregate Root instance fails with an error.
Types ¶
type Applier ¶
type Applier interface {
// Apply applies the specified Event to the Aggregate Root,
// by causing a state change in the Aggregate Root instance.
//
// Since this method cause a state change, implementors should make sure
// to use pointer semantics on their Aggregate Root method receivers.
//
// Please note, this method should not perform any kind of external request
// and should be, save for the Aggregate Root state mutation, free of side effects.
// For this reason, this method does not include a context.Context instance
// in the input parameters.
Apply(eventually.Event) error
}
Applier is the segregated interface, part of the Aggregate Root interface, that describes the left-folding behavior of Domain Events to update the Aggregate Root state.
type BaseRoot ¶
type BaseRoot struct {
// contains filtered or unexported fields
}
BaseRoot segregates and completes the aggregate.Root interface implementation when embedded to a user-defined Aggregate Root type.
BaseRoot provides some common traits, such as tracking the current Aggregate Root version, and the recorded-but-uncommitted Domain Events, through the aggregate.RecordThat function.
type ID ¶
ID represents an Aggregate ID type.
Aggregate IDs should be able to be marshaled into a string format, in order to be saved onto a named Event Stream.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is an Event-sourced Repository implementation for retrieving and saving Aggregate Roots, using an underlying Event Store instance.
Use `NewRepository` to create a new instance of this type.
func NewRepository ¶
func NewRepository(aggregateType Type, eventStore eventstore.Store, options ...RepositoryOption) *Repository
NewRepository creates a new instance for retrieving and saving Aggregate Roots of the Aggregate type specified in the supplied Type argument.
func (*Repository) Add ¶
func (r *Repository) Add(ctx context.Context, root Root) error
Add saves the provided Aggregate Root instance into the Event Store, by flushing any uncommitted event produced while handling commands.
An error is returned if the underlying Event Store fails to commit the Aggregate's events.
func (Repository) Get ¶
Get retrieves the Aggregate Root instance identified by the provided ID.
ErrRootNotFound is returned if no Events for the specified Aggregate Root have been found.
An error is also returned if the underlying Event Store fails to stream the Root's Event Stream back into the application.
type RepositoryOption ¶
type RepositoryOption interface {
// contains filtered or unexported methods
}
RepositoryOption is an optional argument to build a Repository interface to extend its default functionality.
func RepositoryWithSnapshotPolicy ¶
func RepositoryWithSnapshotPolicy(policy snapshot.Policy) RepositoryOption
RepositoryWithSnapshotPolicy uses the provided Snapshot policy to decide whether to take a snapshot of the state, when Add() is called.
The default policy used by the Repository is snapshot.NeverPolicy, which never writes anything to the Snapshot store.
Remember to provide a non-nil Snapshot store isntance using RepositoryWithSnapshotStore, otherwise the Repository will skip the snapshotting logic.
func RepositoryWithSnapshotStore ¶
func RepositoryWithSnapshotStore(store RepositorySnapshotStore) RepositoryOption
RepositoryWithSnapshotStore uses the provided Snapshot store instance to retrieve and save periodical Aggregate Root snapshots, following the Snapshot Policy provided to the Repository.
Remember to set a proper Snapshot Policy to make use of the Store, as the default behavior from the Repository is to never perform one.
type RepositorySnapshotStore ¶
RepositorySnapshotStore is the Snapshot Store interface used by the Repository.
type Root ¶
type Root interface {
Applier
AggregateID() ID
Version() int64
// contains filtered or unexported methods
}
Root is the interface describing an Aggregate Root instance.
This interface should be implemented by your Aggregate Root types. Make sure your Aggregate Root types embed the aggregate.BaseRoot type to complete the implementation of this interface.
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type represents the type of an Aggregate, which will expose the name of the Aggregate (used as Event Store type) and a factory method to create new instances of the type, without using reflection.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package snapshot provides support for Aggregate Root snapshots, useful where the size of your Aggregate Roots is expected to considerably grow in size and number of events.
|
Package snapshot provides support for Aggregate Root snapshots, useful where the size of your Aggregate Roots is expected to considerably grow in size and number of events. |