Esempio n. 1
0
        public async Task FollowStream(Guid streamId, IStreamManager streamManager, IAggregateSettings aggregateSettings)
        {
            _streamId          = streamId;
            _streamManager     = streamManager;
            _aggregateSettings = aggregateSettings;

            var commitMinimumRevision = 0;

            _stream = await _streamManager.GetStream(_streamId).ConfigureAwait(false);

            if (_stream.SnapshotRevision > 0)
            {
                var snapshot = await _streamManager.GetSnapshot(_stream.StreamId, _stream.SnapshotRevision);

                AggregateDataStructure = (T)snapshot.SnapshotData;
                commitMinimumRevision  = snapshot.SnapshotHeadCommit + 1;
            }

            var commits = await _streamManager.GetCommits(_streamId, commitMinimumRevision).ConfigureAwait(false);

            var events = commits
                         .OrderBy(x => x.CommitNumber)
                         .Select(x => x.Event);

            foreach (var @event in events)
            {
                ApplyEvent(@event);
            }
        }
        public static IServiceCollection RegisterEventSourcing(this IServiceCollection services, IAggregateSettings aggregateSettings)
        {
            services.AddSingleton(aggregateSettings);
            services.AddSingleton<IEventStreamReader, EventStreamReader>();

            return services;
        }
Esempio n. 3
0
 public EventStreamReader(IStreamManager streamManager, IAggregateSettings aggregateSettings)
 {
     _streamManager     = streamManager;
     _aggregateSettings = aggregateSettings;
 }