private Something() { Register <SomethingHappened>(e => { _identifier = new SomethingIdentifier(e.SomethingId); _somethingHappened = true; }); Register <SomethingElseHappened>(_ => _somethingElseHappened = true); }
public static Something Happens(SomethingIdentifier identifier) { var something = Factory(); something.Apply(new SomethingHappened { SomethingId = identifier.ToGuid() }); return(something); }
public async Task <Something> GetById( SomethingIdentifier identifier, CancellationToken cancellationToken = default) { var streamId = GetStreamId(identifier); if (UnitOfWork.Current.TryGet(streamId, out var aggregateRoot)) { return((Something)aggregateRoot); } var something = Something.Factory(); await something.LoadFromHistory(ReadEvents(streamId, cancellationToken)); UnitOfWork.Current.Add(streamId, something); return(something); }
private static string GetStreamId(SomethingIdentifier identifier) => $"something-{identifier.ToGuid():n}";