Matster2
Matster2

Reputation: 147

DDD Events Between Aggregates Example

I have two aggregates

item and price adjustment.

A price adjustment will contain an item adjustment which will say, for a specific item, raise it by x percent (e.g. 10%)

my item has a list price which is what needs to be updated/adjusted.

so when the price adjustment is processed, it is going to find that item and needs to adjust that item's list price by the percentage specific. When the adjustment is complete, the item adjustment in the price adjustment needs to be marked as complete

My question is how is this updating of the list price and marking of the item adjustment being performed composed into events?

What is the correct way for me to both update the list price and mark the item adjustment as completed following events?

Is this a correct solution?:

if this is the correct way, should the new calculated list price be added to the ItemListPriceAdjusted price, or should just the adjustment percentage be added and this is then calculated when it is applied/read from the aggregate?

Thanks

Edit:

The option i currently went with is when the price adjustment is being processed, it will go through each of the item adjustments.

It will find the item that it targets and call the function AdjustPrice(Guid priceAdjustmentId, decimal adjustmentPercentage)

This will calculate the new list price for that item and the item will emit an ItemPriceAdjusted event, which contains the price adjustment id, the and the new list price

The price adjustment will then listen for these events and mark the relevant item adjustment as complete, in turn emitting its own ItemAdjustmentCompleted Event

Upvotes: 1

Views: 191

Answers (1)

iTollu
iTollu

Reputation: 1069

We are talking DDD here. So the first question I'd ask is what's happening in the business that you want to reflect with code.

It is highly unlikely that a business would decide to "adjust prices" by 10% on the whole assortment. That has something to deal with the pricing strategy. Which is individual to a product or a category of products. So, I'd start with asking the business first.

Next, if in the underlying business you have some dedicated people or departments to deal with the pricing, that would give you the context boundary. Most likely pricing is a separate domain from inventory (listing the products). Most likely there is some base price, the prime cost of a product. Then there are some additional costs, some margin to it which will form the profit. So, by "adjusting" a price - what are you going to achieve? Does it mean that a prime cost changed? Or a margin changed? Or some marketing campaign ended? Figure it out - and you'll get the answer to your question. You'll be able to derive the event name from it.

To sum up: store/fire/raise/dispatch an event that is relevant to THE business.

Upvotes: 1

Related Questions