コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #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));
            });
        }