Exemplo n.º 1
0
        public async Task <SnapshotContainer> LoadSnapshotAsync <TAggregate, TIdentity, TSnapshot>(
            TIdentity identity,
            CancellationToken cancellationToken)
            where TAggregate : ISnapshotAggregateRoot <TIdentity, TSnapshot>
            where TIdentity : IIdentity
            where TSnapshot : ISnapshot
        {
            _log.Verbose(() => $"Fetching snapshot for '{typeof(TAggregate).PrettyPrint()}' with ID '{identity}'");
            var committedSnapshot = await _snapshotPersistence.GetSnapshotAsync(
                typeof(TAggregate),
                identity,
                cancellationToken)
                                    .ConfigureAwait(false);

            if (committedSnapshot == null)
            {
                _log.Verbose(() => $"No snapshot found for '{typeof(TAggregate).PrettyPrint()}' with ID '{identity}'");
                return(null);
            }

            var snapshotContainer = await _snapshotSerilizer.DeserializeAsync <TAggregate, TIdentity, TSnapshot>(
                committedSnapshot,
                cancellationToken)
                                    .ConfigureAwait(false);

            return(snapshotContainer);
        }
 protected override Task LoadSnapshotAsync(TSnapshot snapshot, ISnapshotMetadata metadata, CancellationToken cancellationToken)
 {
     return(snapshotPersistence.GetSnapshotAsync(typeof(TAggregate), base.GetIdentity(), cancellationToken));
 }