コード例 #1
0
        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));
        }
コード例 #2
0
 /// <inheritdoc />
 public byte[]? Metadata(IMetadataFactory factory, IJsonEventSerializer serializer) =>
 _metadata == null ? null : serializer.Serialize(_metadata);
コード例 #3
0
 /// <inheritdoc />
 public byte[] Data(IJsonEventSerializer serializer) =>
 serializer.Serialize(_data);
コード例 #4
0
 public byte[]? MetadataFor <T>(Guid id, EventType <T> type, T data, IJsonEventSerializer serializer)
 {
     return(serializer.Serialize(new { Username }));
 }