1

How simplest get aggregate from aggregate repository without know his ID but knowing of other unique property? For example I have Cart which has ID as AggregateId and ownerId as other property.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
gargi258
  • 829
  • 1
  • 10
  • 16

1 Answers1

2

In CQRS (assuming you have such a system), when transacting against an aggregate root, you need the state of the aggregate to make the decision in order to preserve the invariants.

On the read side, the typical pattern is to project/denormalise/index the data as appropriate to facilitate querying as you'll need it.

So typically, you'll have a projection track each event and index based on the OwnerId to facilitate the querying. If this is only for the purpose of lookup to run some decision processing command, that can be as simple as a map of OwnerId to owned CartIds.


You haven't provided much context; it depends whether you're trying to build an order history system or a shipping etc. You're much likely to get a good answer to any followup question if you explain more about what you're trying to achieve overall

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • 1
    I did it like you said. Just created map of correlations between this two aggregate in context which requires it. – gargi258 May 12 '18 at 06:36