/// <summary>
        /// Enable the Dafda outbox producer implementation, configurable using the <paramref name="options"/>
        /// </summary>
        /// <param name="services">The service collection</param>
        /// <param name="options">Configure the <see cref="OutboxProducerOptions"/></param>
        public static void AddOutboxProducer(this IServiceCollection services, Action <OutboxProducerOptions> options)
        {
            var builder = new ProducerConfigurationBuilder();
            var outboxProducerOptions = new OutboxProducerOptions(builder, services);

            options?.Invoke(outboxProducerOptions);
            var configuration = builder.Build();

            var outboxListener = outboxProducerOptions.OutboxListener;

            if (outboxListener == null)
            {
                throw new InvalidConfigurationException($"No {nameof(IOutboxListener)} was registered. Please use the {nameof(OutboxProducerOptions.WithListener)} in the {nameof(AddOutboxProducer)} configuration.");
            }

            services.AddTransient <IHostedService, OutboxDispatcherHostedService>(provider =>
            {
                var outboxUnitOfWorkFactory = provider.GetRequiredService <IOutboxUnitOfWorkFactory>();
                var loggerFactory           = provider.GetRequiredService <ILoggerFactory>();
                var kafkaProducer           = configuration.KafkaProducerFactory(loggerFactory);
                var producer         = new OutboxProducer(kafkaProducer);
                var outboxDispatcher = new OutboxDispatcher(loggerFactory, outboxUnitOfWorkFactory, producer);

                return(new OutboxDispatcherHostedService(outboxListener, outboxDispatcher));
            });
        }
        public static void AddOutboxProducer(this IServiceCollection services, Action <OutboxProducerOptions> options)
        {
            var builder = new ProducerConfigurationBuilder();
            var outboxProducerOptions = new OutboxProducerOptions(builder, services);

            options?.Invoke(outboxProducerOptions);
            var configuration = builder.Build();


            services.AddTransient <IHostedService, OutboxDispatcherHostedService>(provider =>
            {
                var outboxUnitOfWorkFactory = provider.GetRequiredService <IOutboxUnitOfWorkFactory>();
                var kafkaProducer           = configuration.KafkaProducerFactory();
                var producer           = new OutboxProducer(kafkaProducer);
                var outboxNotification = provider.GetRequiredService <IOutboxNotification>();

                return(new OutboxDispatcherHostedService(
                           outboxUnitOfWorkFactory,
                           producer,
                           outboxNotification
                           ));
            });
        }
예제 #3
0
 public OutboxDispatcher(ILoggerFactory loggerFactory, IOutboxUnitOfWorkFactory unitOfWorkFactory, OutboxProducer producer)
 {
     _logger            = loggerFactory.CreateLogger <OutboxDispatcher>();
     _unitOfWorkFactory = unitOfWorkFactory;
     _producer          = producer;
 }
예제 #4
0
 public OutboxDispatcherBuilder With(OutboxProducer producer)
 {
     _producer = producer;
     return(this);
 }
예제 #5
0
 public OutboxDispatcher(IOutboxUnitOfWorkFactory unitOfWorkFactory, OutboxProducer producer)
 {
     _unitOfWorkFactory = unitOfWorkFactory;
     _producer          = producer;
 }