var tx = new Transaction(); tx.Post(amount, fromAccount, toAccount); transactionRepository.Store(tx);
|
这是调用Transaction这个聚合根的post方法。方法内部代码:
public void Post(decimal amount, string fromAccount, string toAccount) { this.Apply(new AccountDebited(amount, fromAccount)); this.Apply(new AccountCredited(amount, toAccount)); }
|
将转账命令(转账上游事件)分为两个事件,AccountDebited和AccountCredited,账户借款和账户贷款,这样保证借贷平衡。然后根据借贷状态切换,还有更多子状态,EventStore应该是这些和状态直接有关的事件,间接有关事件没有必要记录,这样在事件回放时才能重现状态真实改变历史。
总结,上面总体架构涉及到是:REST+CQRS+DDD Aggregate + Domain Events + EventSourcing
https://www.jdon.com/45622