EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Non Aggregate Event Support

Open JC008 opened this issue 10 years ago • 4 comments

A formalized EventFlow mechanism is required to provide events that can be subscribed to without reference to an AggregateRoot or Identity and is conceptually similar to delegates but managed by EventFlow.

Use Case

Tracking the count of items in a collection managed by an aggregate.

An AggregateRoot emits an event that an AggregateState applies that results in an item added to a collection managed by the AggregateState. To notify the world that the count of collection items have changed, there are two options:

  1. Use the AggregateState's item count + 1 and Emit as final count of items value as a single event in the Aggregate or
  2. Emit an event that is handled by the AggregateState that adds a new item to the collection and then Emit a second event following the first in the Aggregate with the total items in the collection as reported by the AggregateState

Using approach 1 feels wrong even though the AggregateState does not / should not apply any logic but only record events and do a build-up of the state over time in response to events which in this case has not been actually been applied.

Using approach 2 results in empty and unneeded IApply implementations due to the fact that the event must have an implementation to avoid an Aggregate 'X' does have an 'Apply' method that takes aggregate event 'Y' as argument exception but the event is only of interest to a ISubscriber or possibly a IReadModel.

JC008 avatar Dec 08 '15 15:12 JC008

If the new event is not related to a aggregate, then it would not be added to any event streams, is that correctly understood?

If yes, then I guess it isn't a event that important to your domain and I personally wouldn't use EventFlow for propagating that event, but instead publishing that from a subscriber using another mechanism. Again, if the event isn't related to an aggregate, then I guess that other parts of the application could emit the event as well and using an alternate implementation would ensure that those components aren't dependent on EventFlow as well.

If you want to implement it yourself, then the implementation should be straightforward as you could look at how EventFlow does the resolve of subscribers.

Any thoughts @JC008?

rasmus avatar Feb 19 '16 15:02 rasmus

The problem is related to cross domain event subscribers and information changing in the aggregate which is only known after an event is emitted. The following events where emitted after a catalog and two catalog groups where added following approach 2 above:

{"NewCatalog":{"Description":"test","Icon":"archive","Name":"80s Music","Owner":"cc4b1e5d-b662-5505-b882-ea4658b519b5","Tags":null,"User":"cc4b1e5d-b662-5505-b882-ea4658b519b5"}}

{"NewCatalogGroup":{"Catalog":"dd856a4e-6e7e-5574-ae5a-c5cad5c8c1cc","Description":"test","Icon":"archive","Id":"5bf20e93-3589-5a52-8a6e-e1c51255d406","Name":"Rock","Owner":"cc4b1e5d-b662-5505-b882-ea4658b519b5","Parent":null,"Tags":null,"User":"cc4b1e5d-b662-5505-b882-ea4658b519b5"}}

{"Count":1}

{"NewCatalogGroup":{"Catalog":"dd856a4e-6e7e-5574-ae5a-c5cad5c8c1cc","Description":"test","Icon":"archive","Id":"57e25f18-c7d2-5b20-ba05-58d9f8c85c42","Name":"Pop","Owner":"cc4b1e5d-b662-5505-b882-ea4658b519b5","Parent":null,"Tags":null,"User":"cc4b1e5d-b662-5505-b882-ea4658b519b5"}}

{"Count":2} 

The catalog group count can only be updated in the catalog aggregate after NewCatalogGroup events are handled in the IApply handlers in the AggregateState resulting in the Count update events.

The Count events looks too simple to be a domain event and there is no data mutation in the actual event - it's just a state change broadcast.

This could be a common use case which requires formal support in EventFlow or a formal set of community extensions vetted by you to ensure the core EventFlow remains focused but extensible.

JC008 avatar Feb 20 '16 09:02 JC008

@rasmus I will code a proof of problem for this so we can see if its a domain design issue and discuss it with reference to a working sample.

JC008 avatar Feb 20 '16 16:02 JC008

@JC008 Thanks, that would really help :smile:

rasmus avatar Feb 20 '16 16:02 rasmus

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days. We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards, EventFlow

github-actions[bot] avatar Apr 08 '23 13:04 github-actions[bot]

Hello there!

This issue has been closed due to inactivity for seven days. If you believe this issue still needs attention, please feel free to open a new issue or comment on this one to request its reopening.

Thank you for your contribution to this repository.

Best regards, EventFlow

github-actions[bot] avatar Apr 16 '23 09:04 github-actions[bot]