GithubHelp home page GithubHelp logo

Event is mutable about m-r HOT 1 OPEN

gregoryyoung avatar gregoryyoung commented on June 20, 2024 5
Event is mutable

from m-r.

Comments (1)

EnricoMassone avatar EnricoMassone commented on June 20, 2024 2

Hi @beachwalker ,

I know that this issue is quite old, but I would like to contribute.

The reason for which the Event class is mutable is related to the need of assigning the right version to the event itself, when the event is appended to the event stream. This is done right after the optimistic concurrency check in the EventStore class, see here at line 62.

Two subjects somewhat related to this are the issue #7 and the issue #31 that I recently opened in order to better understand what is the semantic of the Version property.

If my interpretation of the Version property is fine (see #31 for details), we could submit a pull request in order to fix both this issue and #7 . This is the top level plan:

  • fix the issue #7 so that each time an event is applied to the aggregate state the Version property is incremented by 1 (it must be clear how to initialize the counter of the aggregate version. I guess that in Greg's view the aggregate version should be zero after applying the first event. Anyway, it's just a matter of preference, we should only agree on a convention).
  • change the Event base class so that the Version property becomes read only. We could add a protected constructor requesting the value for Version as its sole parameter
  • change the code which raises an event inside the aggregate, so that the value for Event.Version is passed inside the event constructor as this.Version + 1 (the current aggregate version plus one).
  • the optimistic concurrency check in the EventStore class will stay the same, the only change is removing the code at line 62 in the EventStore class (because the Event.Version property won't be writable anymore).

I'm quite confident that assigning the Version to an event in advance (before performing the optimistic concurrency check) won't break anything on the correctness side: if there are concurrency issues the events won't be appended to the event stream so the Version assigned to them is not relevant. Otherwise, in case of a successful optimistic concurrency check, the event Version assigned this way is exactly the same as the one assigned by the currently existing code (because the command is performed against the most recent aggregate version available and, when the events are saved, the aggregate version in the event store is not changed because the optimistic concurrency check was successful).

from m-r.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.