public async Task Store <T>(T aggregate) where T : Aggregate { if (aggregate == null) { throw new ArgumentNullException(nameof(aggregate)); } if (aggregate.Changes.Count == 0) { return; } var stream = StreamName.For <T>(aggregate.GetId()); var expectedVersion = new ExpectedStreamVersion(aggregate.Version); await _eventStore.AppendEvents(stream, expectedVersion, aggregate.Changes.Select(ToStreamEvent).ToArray()); JsonStreamEvent ToStreamEvent(object evt) => new(TypeMap.GetTypeName(evt), _serializer.Serialize(evt)); }
/// <inheritdoc /> public byte[]? Metadata(IMetadataFactory factory, IJsonEventSerializer serializer) => _metadata == null ? null : serializer.Serialize(_metadata);
/// <inheritdoc /> public byte[] Data(IJsonEventSerializer serializer) => serializer.Serialize(_data);
public byte[]? MetadataFor <T>(Guid id, EventType <T> type, T data, IJsonEventSerializer serializer) { return(serializer.Serialize(new { Username })); }