コード例 #1
0
ファイル: CreateBookSaga.cs プロジェクト: khdevnet/mongodb
        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);
        }
コード例 #2
0
ファイル: CreateBookSaga.cs プロジェクト: khdevnet/mongodb
        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);
        }