public async Task Handle(CreateBookCommand request, CancellationToken cancellationToken) { var createdEvent = new BookCreatedEvent(request.Id, request.Book); using (var transaction = new TransactionScope()) { bookSagaEventRepository.Add(ConvertEvent(createdEvent)); transaction.Complete(); } await mediator.Publish(createdEvent); }
public async Task Handle(BookCreatedEvent request, CancellationToken cancellationToken) { var eventData = new BookReadSavedEvent(request.Id, request.Book); using (var transaction = new TransactionScope()) { bookReadRepository.Add(new Book { Id = request.Id, Author = request.Book.Author, Title = request.Book.Title, Status = request.Status }); bookSagaEventRepository.Add(ConvertEvent(eventData)); transaction.Complete(); } await mediator.Publish(eventData); }