public async Task SaveEventsAsync(IEntityId aggregateId, int version, IReadOnlyCollection <IDomainEvent> events) { var stream = $"{aggregateId.GetType().Name}-{aggregateId.ToString()}"; await Connection.AppendToStreamAsync(stream, version, events.Select(e => { var json = Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(e, SerializerSettings)); return(new EventData(Guid.NewGuid(), e.GetType().Name, true, json, new byte[] { })); })); }
public async Task <IReadOnlyCollection <IDomainEvent> > LoadEventsAsync(IEntityId aggregateId) { var stream = $"{aggregateId.GetType().Name}-{aggregateId.ToString()}"; var streamEvents = await Connection.ReadStreamEventsForwardAsync(stream, 0, 4096, false); return(streamEvents.Events .Select(DeserializeDomainEvent) .ToList() .AsReadOnly()); }