Search code examples
javadomain-driven-design

Agrregate root, Factory and partial aggregate


I have an aggregate root called Configuration which represent's all the options configured for a particular provisioned customer on a multi-tenant application. Since there are lot of options to be configured, the user generally follows a series of steps (through wizards) and then sometimes wants to partially save the data to be completed later (may be next day).

I am familiar with the Factory concept and one of its rule is not to enabled creation of partial aggregate objects if they fail the invariant rules.

My question is how to solve the partial object use-case?


Solution

  • If you want to prevent an entity being in a incomplete state, and if you are storing that partially-filled entity just for storing the intermediate request (instead of treating it as one entity), you may have a separate entity to represent the "Creation Request". It makes sense to me that Creation Request (which you can treat that as a factory or input to a factory, in another aspect) can be partially filled and persisted, and upon complete, be used to create the actual entity you want.