public void AlterPickup( ReverseAuctionAggregate aggregate, string pickupAddress) { var pickup = _locationFactory.New(pickupAddress); aggregate.Root.BuyerTerms.ChangePickup(pickup); _interAggregateEventBus.Publish(new Event.BuyerTermsChanged(aggregate)); }
public void WithdrawNow(BidAggregate agg) { if (agg.IsWithdrawn) { return; } agg.Root.WithdrawNow(_deps); _bus.Publish(new Event.BidWithdrawn(agg)); }
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); }
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); }