I am new to Axon and struggling a bit to write a prototype for a very simple service which can be summarized as follows:
- It stores immutable documents
- Documents are identified by an id and a version number (both are client provided)
- Version number are not expected to be continuous (client are free to use the versioning scheme they like)
- Clients can push versions out of order
- Trying to store a document for an already existing document id & version number should be rejected, or accepted if and only the payload is exactly the same, or always accepted (business rules aren’t defined yet).
Command & domain layers are very thin, meat of the service will in queries and I expect ES / CQRS will be useful for that.
My problem is that I don’t know how to manage aggregate roots, more especially how and when to create them. Unlike Axon-bank & Axon-trader, it seems that I don’t have a dedicated command to create an aggregate root. The only command I have is “StoreDocument”. I expect the command handler to automatically creates the aggregate root if needed.
I have tried several different approaches but none of them satisfies me or even work. Any advice or code sample would be appreciated. Or is my modeling just plain wrong?