Exemple #1
0
 internal BiddingNotAllowedNow(
     ReverseAuctionAggregate reverseAuction,
     IClock clock)
     : base(
         $"at {clock.Now}, bidding is not allowed on " +
         $"ReverseAuction {reverseAuction.Id}")
 {
 }
Exemple #2
0
            private void BiddingMustBeAllowedNow(ReverseAuctionAggregate reverseAuction)
            {
                Precondition.MustNotBeNull(reverseAuction, nameof(reverseAuction));

                if (!reverseAuction.BiddingAllowed.Includes(_clock.Now))
                {
                    throw new BiddingNotAllowedNow(reverseAuction, _clock);
                }
            }
Exemple #3
0
            public void AlterPickup(
                ReverseAuctionAggregate aggregate,
                string pickupAddress)
            {
                var pickup = _locationFactory.New(pickupAddress);

                aggregate.Root.BuyerTerms.ChangePickup(pickup);

                _interAggregateEventBus.Publish(new Event.BuyerTermsChanged(aggregate));
            }
            public DomainAuction.ReverseAuctionAggregate Update(
                DomainAuction.ReverseAuctionAggregate ra)
            {
                if (ra.Id == Saved.Id)
                {
                    return(ra);
                }

                throw new ArgumentException($"unknown Id: {ra.Id}");
            }
Exemple #5
0
            public Bid.BidAggregate PlaceBid(
                ReverseAuctionAggregate reverseAuction,
                TimeRange pickupTime,
                TimeRange dropoffTime,
                Money price)
            {
                Precondition.MustNotBeNull(reverseAuction, nameof(reverseAuction));

                // RULE: We'd like to delegate validation and precondition
                // checking to Factorys.  That keeps the Aggregate code
                // clean and simple...
                // but we need to enforce a relationship between the Auction
                // and the new Bid.

                BiddingMustBeAllowedNow(reverseAuction);
                BidMustConformToAuctionTime(
                    reverseAuction.Root.BuyerTerms.Pickup,
                    nameof(pickupTime),
                    pickupTime);
                BidMustConformToAuctionTime(
                    reverseAuction.Root.BuyerTerms.Dropoff,
                    nameof(dropoffTime),
                    dropoffTime);
                PriceMustBeNonNegative(price);

                var bid = _bidFactory.New(
                    reverseAuction.Id,
                    pickupTime,
                    dropoffTime,
                    price);

                // TODO: According to IDDD, we'd publish a "created" event
                // here.  I need to fit this into the context of our work
                // to wrap DB transactions around business interactions.
                // OTOH, there may be no conflict if the domain event
                // publisher is flexible enough that in test the event is
                // published immediately but in production the event is
                // only published when the transaction is committed.
                // However, if the consistency boundary IS the aggregate,
                // it may not be reasonable to wait.

                var aggregate = new Bid.BidAggregate(bid);

                _interAggregateEventBus.Publish(
                    new Bid.Event.BidCreated(aggregate));

                return(aggregate);
            }
Exemple #6
0
            public ReverseAuctionAggregate New(
                string pickupAddress,
                TimeRange pickupTime,
                string dropoffAddress,
                TimeRange dropoffTime,
                string otherTerms,
                TimeRange biddingAllowed)
            {
                // RULE: All validation and precondition checking
                // is delegated down to the Factorys.  That keeps the
                // Aggregate code clean and simple.

                // TODO: Ideally, exposing this at the aggregate level has the
                // potential to allow all the Entity Factorys themselves to be
                // hidden within this assembly, and never used outside it
                // I haven't figured out how to do that, in practice.

                var pickup = new Waypoint(
                    _locationFactory.New(pickupAddress),
                    pickupTime);
                var dropoff = new Waypoint(
                    _locationFactory.New(dropoffAddress),
                    dropoffTime);
                var auction = _reverseAuctionFactory.New(
                    _termsFactory.New(pickup, dropoff, otherTerms),
                    biddingAllowed);

                // TODO: According to IDDD, we'd publish a "created" event
                // here.  I need to fit this into the context of our work
                // to wrap DB transactions around business interactions.
                // OTOH, there may be no conflict if the domain event
                // publisher is flexible enough that in test the event is
                // published immediately but in production the event is
                // only published when the transaction is committed.
                // However, if the consistency boundary IS the aggregate,
                // it may not be reasonable to wait.

                var aggregate = new ReverseAuctionAggregate(auction);

                _interAggregateEventBus.Publish(
                    new Event.ReverseAuctionCreated(aggregate));

                return(aggregate);
            }
 public DomainAuction.ReverseAuctionAggregate Save(
     DomainAuction.ReverseAuctionAggregate ra)
 {
     throw new NotImplementedException();
 }