outsidenote / eventualize

5 stars 0 forks source link

Multi Domain Stream #1

Closed bnayae closed 4 days ago

bnayae commented 10 months ago

When a stream serves multiple domains, such as an E-commerce operation comprising domains like marketing, ordering, and shipment. Determining ownership is not a straightforward matter. This creates a dilemma regarding which domain should take charge of the 'aggregator.' The decision to share a stream across multiple domains arises when the events of orders matter.

outsidenote commented 10 months ago

Sharing my thoughts about how we can go about this:

What differentiates one aggregate from another one that are reading from the same stream is the folding logic (The state type is not a good enough differentiator as 2 different folding logics can create the same state type, but with different values). That means that when we instantiate an Aggregate, we need to provide a FoldingLogic to it. A Folding Logic would have an identifier, it'll hold the type of the state, and the mapping of event types to folding functions. Something like this:

class FoldingLogic<TState>: IFoldingLogic
{
  public string Name {get; private set;}
  private IDictionary<string, IFoldingFunction<TState>> FoldingFunctions;
}

class Aggregate<TState,IFoldingLogic>{}

BTW, I think we can neglect for now the fact the different services might create different FoldingLogics with the same name.