modernice/goes

Built-in `Deleted` and `Restored` events

Opened this issue · 0 comments

Example:

package auth

type User struct { *aggregate.Base }

func (u *User) Delete() {
  aggregate.Delete(u)

  // will be called under the hood:
  aggregate.Next(u, aggregate.Deleted, aggregate.Deletion{})
}

func (u *User) Restore() {
  aggregate.Restore(u)

  // will be called under the hood:
  aggregate.Next(u, aggregate.Restored, aggregate.Restoration{})
}

A new codec.Option will be added to the aggregate package to register the built-in deletion events:

package example

func example() {
  r := codec.New(aggregate.BuiltinEvents())
}

Maybe add a new helper that automatically registers builtin events:

package example

func example() {
  r := aggregate.NewEventRegistry()
}