Created
July 11, 2022 20:50
-
-
Save n1ckdm/54146b9560eee52267baae57b66f6849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private async Task<Game> GetCurrentState(Guid gameId) => | |
(await _repository.Load(gameId)).Aggregate(new Game(), (g, e) => Game.Apply(g, e)); | |
private List<IEvent> SendToAggregate(ICommand command, Game game) => | |
command switch | |
{ | |
CreateGameCommand c => game.Handle(c), | |
MakeMoveCommand c => game.Handle(c), | |
_ => throw new NotImplementedException() | |
}; | |
public async Task Handle(ICommand cmd) | |
{ | |
Game game = await GetCurrentState(cmd.GameId); | |
List<IEvent> events = SendToAggregate(cmd, game); | |
await _repository.Save(cmd.GameId, events); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment