Comments (5)
In addition you need to set a maxVersion in https://github.com/event-engine/php-engine/blob/master/src/Aggregate/GenericAggregateRepository.php#L210 while the eventstore can load events without maxVersion.
from php-engine.
Oh sorry, I was confused by the word state. But now, I see, I'm retrieving the aggregate root. But my second question is still valid.
from php-engine.
I created a pull request for it: #9
from php-engine.
Hi,
I think in event-engine, you need to restore it via the EventEngine class?
Yes, but only if you need the aggregate state outside of its own boundary to make decisions elsewhere (f.e. in a process manager or another aggregate) or want to use it as a read model. When handling commands, Event Engine will load the aggregate and restore current state. You don't need an extra collection for that.
When using the OopFlavour aggregate state === aggregate instance, because state of the aggregate is part of it. But even when using the OopFlavour I highly recommend to pass read-only aggregate state around instead of the aggregate instance itself. For example our OOP aggregates only have one private state
property. And this state
is an immutable object. When the aggregate handles a command, it records an event and in the corresponding event apply function uses something like:
final class User
{
// PHP 7.4 property type hint ;)
private UserState $userState;
// ...
private function whenUsernameChanged(UsernameChanged $event)
{
// Replace immutable state with new version
$this->userState = $this->userState->with([UserState::NAME => $event->newUsername()]);
}
public function state(): UserState
{
return $this->userState;
}
}
As you can see the aggregate root provides a method to retrieve its immutable state. Only return this state from a UserCollection
! No part of your code should have access to state changing methods of your aggregates. Only commands can trigger state changes and EE takes care of passing a command to a fresh aggregate instance with latest state restored.
EventEngine::loadAggreateState()
gives you the latest aggregate (state) using a snapshot from the document store if available + newer events (if snapshot is behind)
EventEngine::loadAggregateStateUnil()
is meant to be used only if you need aggregate (state) at a certain point in time (time travels). This is handy for some advanced use cases or projections that rely on aggregate state at the time when the corresponding event was recorded. The latter should be avoided, but that's not always possible.
from php-engine.
Thx Alexander for the detailed explanation and handy tips. It's clear for me now!
from php-engine.
Related Issues (15)
- Check uniqueness of Command, Query and Event names HOT 3
- meaning of CommandDispatchResult HOT 4
- EventEngine::rebuildAggregateState does not work as expected with MultiModelStore HOT 1
- Using the specification pattern in combination with Event Engine HOT 4
- Describe differences between original project and fork HOT 1
- How does migration work? HOT 2
- Next Gen Event Engine
- Context Providers should also receive the state if exists HOT 2
- Support dedicated dispatcher for commands
- Method fromCachedConfig should only load config
- New release please? HOT 2
- Any roadmap? HOT 3
- Cannot rewind a generator that was already run HOT 3
- Process manager in event-engine HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-engine.