예제 #1
0
        public static Outbox Restore(string requestId,
                                     long aggregateId,
                                     bool isStored,
                                     bool isDispatched,
                                     object response,
                                     IEnumerable <object> commands,
                                     IEnumerable <object> events)
        {
            var instance = new Outbox(requestId, aggregateId, isStored, isDispatched)
            {
                Response = response
            };

            if (commands != null)
            {
                instance._commands.AddRange(commands);
            }

            if (events != null)
            {
                instance._events.AddRange(events);
            }

            return(instance);
        }
        public async Task EnsureDispatched(Outbox outbox, IOutboxDispatcher dispatcher)
        {
            if (outbox.IsDispatched)
            {
                return;
            }

            foreach (var command in outbox.Commands)
            {
                await dispatcher.Send(command);
            }

            foreach (var evt in outbox.Events)
            {
                await dispatcher.Publish(evt);
            }

            await _repository.Save(outbox, OutboxPersistingReason.Dispatching);

            outbox.IsDispatched = true;
        }
예제 #3
0
        public static Outbox Restore(string idempotencyId,
                                     bool isDispatched,
                                     object response,
                                     IEnumerable <object> commands,
                                     IEnumerable <object> events)
        {
            var instance = new Outbox(idempotencyId, isClosed: true, isDispatched)
            {
                Response = response
            };

            if (commands != null)
            {
                instance._commands.AddRange(commands);
            }

            if (events != null)
            {
                instance._events.AddRange(events);
            }

            return(instance);
        }
예제 #4
0
        public async Task <Outbox> Open(string idempotencyId)
        {
            var existingOutbox = await _repository.GetOrDefault(idempotencyId);

            return(existingOutbox ?? Outbox.Open(idempotencyId));
        }
 public Task Save(Outbox outbox, OutboxPersistingReason reason)
 {
     throw new InvalidOperationException("Outbox repository is not configured. To use outbox, you need to configure repository in service.AddOutbox(c => {...})");
 }
        public async Task Store(Outbox outbox)
        {
            await _repository.Save(outbox, OutboxPersistingReason.Storing);

            outbox.IsStored = true;
        }