Ejemplo n.º 1
0
        public async Task <TProjection> GetProjection <TProjection>(string id)
            where TProjection : Projection, new()
        {
            var eventStoreConnection = _eventStoreBuilder.GetConnection();

            var events = await eventStoreConnection.ReadStreamEventsForwardAsync(id, 0, 1000, true);

            return(await Hydrate <TProjection>(events));
        }
Ejemplo n.º 2
0
        public async Task SaveAggregate <TAggregate>(TAggregate aggregate, long version)
            where TAggregate : AggregateRoot, new()
        {
            var eventStoreConnection = _eventStoreBuilder.GetConnection();

            var events = aggregate.Events
                         .Select(e => new EventData(Guid.NewGuid(), e.GetType().Name, true, e.Serialize(), null))
                         .ToArray();

            aggregate.ClearEvents();

            await eventStoreConnection.AppendToStreamAsync(aggregate.Id.ToString(), version, events);
        }