コード例 #1
0
        /// <summary>
        /// Finds an aggregate, runs the update handler and saves the aggregate
        /// </summary>
        /// <typeparam name="T">Type of the aggregate</typeparam>
        /// <param name="repository">repository instance</param>
        /// <param name="id">the aggregate id</param>
        /// <param name="handler">the update handler</param>
        /// <returns>A Task containing the updated aggregate</returns>
        public static async Task <T> Update <T>(this IAggregateRepository <T> repository, string id, Action <T> handler)
            where T : IAggregate
        {
            var aggregate = await repository.Find(id);

            handler(aggregate);

            await repository.Save(aggregate);

            return(aggregate);
        }
コード例 #2
0
        public async Task Handle(AddBidCommand command)
        {
            var auction = await _auctionRepository.Find(command.Id);

            if (auction is null) // Todo: in case of asynchornous command handling - should this validation be moved to the command initiator (i.e. API)?
            {
                throw new InvalidOperationException($"auction id: {command.Id} not found");
            }

            auction.AddBid(command.ItemId, command.Bidder, command.Amount, command.BidTimestamp);

            await _auctionRepository.Update(auction);
        }
コード例 #3
0
        public async Task Handle(AdditemToAuctionCommand message)
        {
            var auction = await _auctionRepository.Find(message.AuctionId);

            auction.AddItem(message.Item.Name, message.Item.Description, message.Item.ReservedPrice);
        }