コード例 #1
0
        public IEnumerable <TAggregate> GetAll()
        {
            var aggregateType = typeof(TAggregate);

            if (!AggregateTypeStreams.TryGetValue(aggregateType, out var aggregateStreams))
            {
                throw new KeyNotFoundException($"Aggregates of type {aggregateType.FullName} not stored in this storage.");
            }
            return(aggregateStreams.Select(pair => (TAggregate)pair.Value));
        }
コード例 #2
0
        /// <inheritdoc />
        public Task <TAggregate> Read(Guid aggregateId)
        {
            var aggregateType = typeof(TAggregate);

            if (!AggregateTypeStreams.TryGetValue(aggregateType, out var aggregateStreams) ||
                !aggregateStreams.TryGetValue(aggregateId, out var aggregate))
            {
                throw new KeyNotFoundException($"An aggregate of type {aggregateType.FullName} with ID {aggregateId} not found.");
            }

            return(Task.FromResult((TAggregate)aggregate));
        }