Question about DDD & Axon


I’m trying to play a little with Axon and DDD. To keep it simple, let’s say we have:

1.The Inventory with many products, which is my candidate as @Aggragate. At some point (it doesn’t matter when), Inventory is created and products are added.

2.An Order which can contain products from the Inventory. Also an @Aggragate

The simple scenario is that a client creates an order with selected products.

In my backend system Order aggragate is created.

Now the difficult part. I’m starting new Saga and I want to send command like this : MarkProductsAsReservedCommandInInventory, but I don’t have any Inventory identifier.

I’ve seen in some similar demo applications that usually the identifier comes from the client but I don’t see any reason why any client (REST, browser, etc.) should know anything about my Inventory.

So what is the typical solution for this type of situation, which I guess happens very often?

Or maybe I misunderstood some key concepts ?

Hi Tomasz,

Not being the subject matter expert for your domain, I might say something which isn’t a good fit.
Regardless, please bear with me here.

From your explanation it sounds like the Order aggregate should be able to instantiate the Inventory aggregate.
If this is the case, you could have your Saga decided the Aggregate identifier for example.
You could however also leave the Inventory Aggregate itself in charge of creating it’s Aggregate Identifier.
Both are perfectly valid scenarios for providing you with a new Aggregate and it’s identifier.

Now, the creation of this Aggregate could indeed be offloaded to a Saga.
Axon however also provides you to instantiate an Aggregate from another Aggregate.
To do so, you can use the static AggregateLifecycle#createNew(Class<T> aggregateType, Callable<T> factoryMethod) method for that.

Would any of these suggestions help you out with your problem, Tomasz?