Пример #1
0
        public async Task HandleAsync(T @event, ICorrelationContext context)
        {
            if (@event.BelongsToSaga())
            {
                var sagaContext = SagaContext.FromCorrelationContext(context);
                await _sagaCoordinator.ProcessAsync(@event, sagaContext);
            }

            switch (@event)
            {
            case IRejectedEvent rejectedEvent:
                await _operationsStorage.SetAsync(context.Id, context.UserId,
                                                  context.Name, OperationState.Rejected, context.Resource,
                                                  rejectedEvent.Code, rejectedEvent.Reason);

                await _operationPublisher.RejectAsync(context,
                                                      rejectedEvent.Code, rejectedEvent.Reason);

                return;

            case IEvent _:
                await _operationsStorage.SetAsync(context.Id, context.UserId,
                                                  context.Name, OperationState.Completed, context.Resource);

                await _operationPublisher.CompleteAsync(context);

                return;
            }
        }
        public async Task HandleAsync(T command, ICorrelationContext context)
        {
            if (!command.BelongsToSaga())
            {
                return;
            }

            var sagaContext = SagaContext.FromCorrelationContext(context);
            await _sagaCoordinator.ProcessAsync(command, sagaContext);
        }