Coder Social home page Coder Social logo

snapshotting's Introduction

Broadway

Broadway is a project providing infrastructure and testing helpers for creating CQRS and event sourced applications. Broadway tries hard to not get in your way. The project contains several loosely coupled components that can be used together to provide a full CQRS\ES experience.

build status

About

Read the blog post about this repository at:

Installation

$ composer require broadway/broadway

Documentation

You can find detailed documentation of the Broadway bundle on broadway.github.io/broadway.

Feel free to join #qandidate on freenode with questions and remarks!

Acknowledgements

The broadway project is heavily inspired by other open source project such as AggregateSource, Axon Framework and Ncqrs.

We also like to thank Benjamin, Marijn and Mathias for the conversations we had along the way that helped us shape the broadway project. In particular Marijn for giving us access to his in-house developed CQRS framework.

License

MIT, see LICENSE.

snapshotting's People

Contributors

alessandrominoccheri avatar dependabot-preview[bot] avatar dependabot[bot] avatar mmalessa avatar othillo avatar wjzijderveld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

snapshotting's Issues

Snapshot does not register aggregate root for EventSourcedEntities

When an event is applied to an aggregate it is handled recursively, meanwhile registering the aggregate root for child entities.

class Broadway\EventSourcing\EventSourcedAggregateRoot {
....
  protected function handleRecursively($event)
  {
        $this->handle($event);

        foreach ($this->getChildEntities() as $entity) {
            $entity->registerAggregateRoot($this);
            $entity->handleRecursively($event);
        }
  }
...
}

Snapshot is just a serialized object. So there is no handling of a snapshot that registers aggregate root for child entities.

If there is at least one event after the snapshot, following method registers the aggregages for child entities;

class Broadway\EventSourcing\EventSourcedAggregateRoot {
....    
public function initializeState(DomainEventStream $stream)
  {
      foreach ($stream as $message) {
          ++$this->playhead;
          $this->handleRecursively($message->getPayload());
      }
  }
...
}

But if there are no events after snapshot, and you want to apply an event to your entities (which in turn would apply the event to the aggregate root, you will get an error;
Call to a member function apply() on null
(see an implementation https://github.com/broadway/broadway/blob/master/src/Broadway/EventSourcing/SimpleEventSourcedEntity.php#L53)

One easy solution is to change EventSourcedAggregateRoot::initializeState method to register aggregate roots for child entities even if there's no event coming after the snapshot.

class Broadway\EventSourcing\EventSourcedAggregateRoot {
....
    public function initializeState(DomainEventStream $stream)
    {

        // added block
        foreach ($this->getChildEntities() as $entity) {
            $entity->registerAggregateRoot($this);
        }

        foreach ($stream as $message) {
            ++$this->playhead;
            $this->handleRecursively($message->getPayload());
        }
    }
...
}

Currently I can override initializeState in my aggregate root. But it would be good if this was done in abstract class
EventSourcedAggregateRoot.

Hope it is clear. Any opinions? Is there something I am missing?
Thanks in advance

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.