internal async Task EnsureDispatched(IOutboxDispatcher dispatcher) { if (!IsClosed) { throw new InvalidOperationException($"The outbox {IdempotencyId} is not closed yet, so it can't be dispatched"); } if (IsDispatched) { return; } var dispatchingTasks = new List <Task>(); foreach (var command in Commands) { dispatchingTasks.Add(dispatcher.Send(command)); } foreach (var evt in Events) { dispatchingTasks.Add(dispatcher.Publish(evt)); } await Task.WhenAll(dispatchingTasks); IsDispatched = true; }
public UnitOfWorkFactory(IOutboxDispatcher defaultOutboxDispatcher, Func <TDbContext> dbContextFactory, Func <TUnitOfWork> unitOfWorkFactory) { _defaultOutboxDispatcher = defaultOutboxDispatcher; _dbContextFactory = dbContextFactory; _unitOfWorkFactory = unitOfWorkFactory; }
/// <summary> /// Initializes transactional unit of work. /// Used internally by Swisschain.Idempotency infrastructure /// </summary> public async Task Init(IOutboxDispatcher defaultOutboxDispatcher, TDbContext dbContext, Outbox outbox) { _dbContext = dbContext; _transaction = await dbContext.Database.BeginTransactionAsync(); var outboxWriteRepository = new OutboxWriteRepository <TDbContext>(dbContext); ProvisionRepositories(dbContext); await Init(defaultOutboxDispatcher, outboxWriteRepository, outbox); }
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; }
public OutboxManager(IOutboxDispatcher dispatcher, IOutboxRepository repository) { _dispatcher = dispatcher; _repository = repository; }