public async Task HandleAsync( IDomainEvent <KontoAggregate, KontoId, KontoEroeffnet> domainEvent, CancellationToken cancellationToken) { var benutzer = domainEvent.AggregateEvent.Benutzer; var query = new KontoByBenutzerQuery(benutzer); try { await this.queryProcessor.ProcessAsync(query, CancellationToken.None); } catch (MehrereKontenMitSelbemBenutzerException) { var id = domainEvent.AggregateIdentity; await this.bus.PublishAsync(new KontoAufloesenCommand(id), CancellationToken.None); } }
public override async Task ExecuteAsync( KontoAggregate aggregate, KontoEroeffnenCommand command, CancellationToken cancellationToken) { var query = new KontoByBenutzerQuery(command.Benutzer, false); if (await this.queryProcessor.ProcessAsync(query, cancellationToken) != null) { throw DomainError.With($"Konto für Benutzer {command.Benutzer} existiert bereits."); } aggregate.Eroeffnen(command.Benutzer); if (command.Bezahlung != null) { aggregate.BezahlungZuordnen(command.Bezahlung); } }