efacilitation/eventric

Global projections

Closed this issue · 6 comments

The idea is to have global projections with the same logic of processManager with from#{domainEvent.context}_handle#{domainEvent.name} method names.

It could declare those methods to eventric global class :
Eventric::addGlobalProjection(name, class)
Eventric::addGlobalProjections(obj)
Eventric::getGlobalProjection(name)

The main question is
How do you want to handle it ?
I think the nice way is to load a projection on each context with a binding on callbacks. This avoid to duplicate projection logic.

But the problem that I don't really know how the right domain events order will be played because initialize functions will be played on each projection separately. I start looking :)

I take choices to have a working concept, we'll discuss those choices afterwards. :)

Hi, we're currently a bit busy. Will get in touch tomorrow about this stuff. Thanks so far!

No problem.

@Sandreu Sorry that we didn´t get in touch recently. We are currently reconsidering how projections work in general. We can leave this issue open and come back to it when the time is right.

Hi @Sandreu,

with the last changes global projections have made their way into eventric in a very simple manner (see: 1828b06).

The syntax is as follows:

// first create and initialize all your contexts
eventric.initializeProjection({
    handleSomethingCreated: function(domainEvent) {
      // handles an event called SomethingCreated regardless from which context
    }
});

The implementation is very simple. It introduces a global context which just delegates all find and subscribe operations to all registered contexts on eventric. Therefore it has two flaws:

  1. When having domain events with the same name in different contexts, you cannot declare separate domain event handlers (both events will trigger the same handler, you can differentiate by checking domainEvent.context)
  2. Since the global contexts simply delegates all operations to all contexts the find operations may not have the ideal performance and some unnecessary event handlers will be registered. Example: if there is FooCreated on Context 1 and BarCreated on Context 2, both Context 1 and 2 will have handlers registered for FooCreated and BarCreated.

Apart from that, it works perfectly fine.