Chris Tickner
Chris Tickner

Reputation: 2017

Transitioning a referenced aggregate root to another aggregate root

My system has the language of a "Contact" which is a sort of "ghost user" that we have some information on - it's validation rules are slim and it's state is largely contact information. We also have a concept of a "User" which is a fully-vetted and registered user. Think of a "User" as a fleshed out "Contact".

The lifecycle we are trying to capture is that a "Contact" will be replaced by a "User" once someone registers with that "Contact"s information.

We have other aggregate roots in the system that make reference to a "ContactId" pointing to the UUID of a "Contact". When that "Contact" registers, we'd like to use a new concept of a "User" to represent them in the domain and the "User" now has it's own "UserID" UUID.

  1. How can we keep relationships that still reference the "Contact" via a ContactID, to now reference the "User" via a UserID?
  2. Is there a fundamental problem with trying to transition my aggregate into another one?
  3. If so, how should I model this particular lifecycle of a "Contact" -> "Registered User"?
  4. If the answer is to merge the two ideas into a single aggregate root, how can I keep my domain objects being valid at all times, despite a "User" not being valid until this "Contact" actually registers?

As a side note, we are using CQRS/ES for the overall architecture.

Thanks!

Upvotes: 2

Views: 156

Answers (1)

Eben Roux
Eben Roux

Reputation: 13256

What you are describing is actually not that strange since it happens all the time.

You could have a ShoppingCart that becomes a Quote that becomes an Order that becomes an Invoice.

Trying to merge concepts usually leads to pain and suffering.

I suggest keeping them separate and handling them with their own life-cycle since they may seem very closely related by they certainly do appear to be concepts distinct from each other.

There may be a clue in your 'ghost user'. That is probably an entity/AR that you are after that hasn't been properly defined. There are going to be different ways of handling that concept depending on how it is being used. It may be as simple as a value object representing wither of the two source entities.

Upvotes: 2

Related Questions