public async Task AddAsync(Topic topic)
        {
            var kafkaDbContext             = new KafkaDbContext(_kafkaDbContextFactory.Create().Options);
            var capabilityServiceDbContext = new CapabilityServiceDbContext(_capabilityServiceDbContextFactory.Create().Options);
            var daoTopic = EntityFramework.DAOs.Topic.CreateFrom(topic);

            await kafkaDbContext.Topics.AddAsync(daoTopic);

            await kafkaDbContext.SaveChangesAsync();

            try
            {
                await _outbox.QueueDomainEvents(topic);

                await capabilityServiceDbContext.SaveChangesAsync();
            }
            catch
            {
                kafkaDbContext.Topics.Remove(daoTopic);

                await kafkaDbContext.SaveChangesAsync();

                throw;
            }
        }
Ejemplo n.º 2
0
        private async Task QueueDomainEvents()
        {
            var aggregates = _dbContext
                             .ChangeTracker
                             .Entries <IAggregateDomainEvents>()
                             .Select(x => x.Entity)
                             .ToArray();

            foreach (var aggregate in aggregates)
            {
                await _outbox.QueueDomainEvents(aggregate);

                aggregate.ClearDomainEvents();
            }
        }