private static IProducerConfiguration ConfigureProducerConfiguration(IServiceCollection services, Action <IProducerOptions> options)
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();
            var configurationBuilder    = new ProducerConfigurationBuilder();

            configurationBuilder.WithOutgoingMessageRegistry(outgoingMessageRegistry);
            var consumerOptions = new ProducerOptions(configurationBuilder, services, outgoingMessageRegistry);

            options?.Invoke(consumerOptions);
            var producerConfiguration = configurationBuilder.Build();

            return(producerConfiguration);
        }
        private static ProducerFactory CreateProducerFactory <TImplementation>(IServiceCollection services, Action <ProducerOptions> options)
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();
            var configurationBuilder    = new ProducerConfigurationBuilder();
            var consumerOptions         = new ProducerOptions(configurationBuilder, outgoingMessageRegistry);

            options?.Invoke(consumerOptions);

            var producerConfiguration = configurationBuilder.Build();

            var factory = AddOrGetRegisteredProducerFactory(services);

            factory.ConfigureProducerFor <TImplementation>(producerConfiguration, outgoingMessageRegistry);
            return(factory);
        }
Example #3
0
        public static void AddProducerFor <TClient>(this IServiceCollection services, Action <ProducerOptions> options) where TClient : class
        {
            var outgoingMessageRegistry = new OutgoingMessageRegistry();
            var configurationBuilder    = new ProducerConfigurationBuilder();
            var consumerOptions         = new ProducerOptions(configurationBuilder, outgoingMessageRegistry);

            options?.Invoke(consumerOptions);

            var producerConfiguration = configurationBuilder.Build();

            var factory = AddOrGetRegisteredProducerFactory(services);

            factory.ConfigureProducerFor <TClient>(producerConfiguration, outgoingMessageRegistry);

            services.AddTransient <TClient>(provider =>
            {
                var producer = factory.GetFor <TClient>();
                return(ActivatorUtilities.CreateInstance <TClient>(provider, producer));
            });
        }