Open bounoable opened 2 years ago
The repository.Repository
type could provide a Prepare()
method that "prepares" the next query/fetch.
package example
func example(repo *repository.Repository) {
var foo aggregate.Aggregate
repo.Prepare(repository.WithSoftDeleted())
repo.Fetch(ctx, foo)
aggregate.Next(foo, "restored", RestoredEvent{})
repo.Save(context.TODO(), foo)
}
*repository.Repository
instead of aggregate.Repository
The repository.Repository
type could provide a FetchDeleted()
and a QueryDeleted()
method.
package example
func example(repo *repository.Repository) {
var foo aggregate.Aggregate
repo.FetchDeleted(ctx, foo)
aggregate.Next(foo, "restored", RestoredEvent{})
repo.Save(context.TODO(), foo)
}
*repository.Repository
instead of aggregate.Repository
Could variadic options not be added to the repository.Fetch
method? It shouldn't be backwards incompatible since all previous calls would not include any extra arguments. This would bring it in line with aggregate stream implementation.
The repository.Fetch
method could provide a repository.WithSoftDeleted(true)
option
package example
func example(repo *repository.Repository) {
var foo aggregate.Aggregate // aggregate whose latest event was a SoftDelete => true
repo.Fetch(ctx, foo, repository.WithSoftDeleted(true))
aggregate.Next(foo, "restored", RestoredEvent{})
repo.Save(context.TODO(), foo)
}
Problem
When the event stream of an aggregate contains a
SoftDeleter
event, the aggregate can neither be queried nor fetched from the aggregate repository. How can an aggregate be restored if it cannot be fetched to raise theSoftRestorer
event?Example
Proposal –
context.Context
APIThe
repository
package could provide a "hidden" API usingcontext.Context.WithValue()
to disable soft-deletion checks:Drawbacks