On our project a number of aggregates have the requirement that they
have a unique name across all instances of the aggregates of a certain
type. To achieve this we created a UniqueNameSet that has the method
boolean doesNameExist(Class aggregateType, String aggregateName)
Other implementations I have seen internally we store the names for an
aggregate in a database table. Our implementation is Event Sourced. We
implement the EventVisitor interface so that when the set loads i.e.
the bean is initialised we visit each event and build up the set of
names for each aggregate type.
What do you think about this approach?
One issue at the moment I see is that the EventVisitor doesnt take
into account the Snapshot mechanism so all domain events need to be
visited. Another point here is that it removes the need to create new
domain querying services and tables and the supporting software
artifacts e.g. tests sql scripts. There are less representation of
same data in domain and there is a performance benefit keeping these
things in memory and not hitting database.