コード例 #1
0
        void IConsumerRegistration.Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider)
        {
            var scopeProvider = configurationServiceProvider.GetRequiredService <IConsumerScopeProvider>();
            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            var decoratorRegistration = configurationServiceProvider.GetService <IConsumerFactoryDecoratorRegistration <TConsumer> >();

            if (decoratorRegistration != null)
            {
                consumerFactory = decoratorRegistration.DecorateConsumerFactory(consumerFactory);
            }

            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            GetConsumerDefinition(configurationServiceProvider)
            .Configure(configurator, consumerConfigurator);

            foreach (Action <IConsumerConfigurator <TConsumer> > action in _configureActions)
            {
                action(consumerConfigurator);
            }

            var endpointName = configurator.InputAddress.GetLastPart();

            foreach (var configureReceiveEndpoint in consumerConfigurator.SelectOptions <IConfigureReceiveEndpoint>())
            {
                configureReceiveEndpoint.Configure(endpointName, configurator);
            }

            LogContext.Info?.Log("Configured endpoint {Endpoint}, Consumer: {ConsumerType}", endpointName, TypeMetadataCache <TConsumer> .ShortName);

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
コード例 #2
0
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, IUnityContainer container, Action <IConsumerConfigurator <T> > configure = null)
            where T : class, IConsumer
        {
            var consumerFactory = new ScopeConsumerFactory <T>(new UnityConsumerScopeProvider(container));

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #3
0
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, IContext context, Action <IConsumerConfigurator <T> > configure)
            where T : class, IConsumer
        {
            var consumerFactory = new ScopeConsumerFactory <T>(new StructureMapConsumerScopeProvider(context));

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #4
0
        /// <summary>
        /// Registers a consumer which is resolved from the service provider, within a container scope
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="serviceProvider">The LifetimeScope of the container</param>
        /// <param name="configure">Configure the consumer (optional)</param>
        /// <returns></returns>
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, IServiceProvider serviceProvider, Action <IConsumerConfigurator <T> > configure = null)
            where T : class, IConsumer
        {
            IConsumerScopeProvider scopeProvider = new DependencyInjectionConsumerScopeProvider(serviceProvider);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #5
0
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="kernel">The LifetimeScope of the container</param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, IKernel kernel, Action <IConsumerConfigurator <T> > configure = null)
            where T : class, IConsumer
        {
            IConsumerScopeProvider scopeProvider = new WindsorConsumerScopeProvider(kernel);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #6
0
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="container">The LifetimeScope of the container</param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, IContainer container, Action <IConsumerConfigurator <T> > configure = null)
            where T : class, IConsumer
        {
            IConsumerScopeProvider scopeProvider = new StructureMapConsumerScopeProvider(container);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #7
0
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="scope">The LifetimeScope of the container</param>
        /// <param name="configure"></param>
        /// <param name="name">The name of the scope created per-message</param>
        /// <returns></returns>
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, Action <IConsumerConfigurator <T> > configure, string name = "message")
            where T : class, IConsumer
        {
            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(new SingleLifetimeScopeProvider(scope), name);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #8
0
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="scope">The LifetimeScope of the container</param>
        /// <param name="name">The name of the scope created per-message</param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, string name = "message",
                                        Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where T : class, IConsumer
        {
            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(new SingleLifetimeScopeProvider(scope), name, configureScope);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory);
        }
コード例 #9
0
        /// <summary>
        /// Connect a consumer with a consumer factory method
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="container"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <TConsumer, TMessage>(this IBatchConfigurator <TMessage> configurator, IContainer container,
                                                          Action <IConsumerMessageConfigurator <TConsumer, Batch <TMessage> > > configure = null)
            where TConsumer : class, IConsumer <Batch <TMessage> >
            where TMessage : class
        {
            IConsumerScopeProvider scopeProvider = new StructureMapConsumerScopeProvider(container);

            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #10
0
        /// <summary>
        /// Connect a consumer with a consumer factory method
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="provider"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <TConsumer, TMessage>(this IBatchConfigurator <TMessage> configurator, IServiceProvider provider,
                                                          Action <IConsumerMessageConfigurator <TConsumer, Batch <TMessage> > > configure = null)
            where TConsumer : class, IConsumer <Batch <TMessage> >
            where TMessage : class
        {
            IConsumerScopeProvider scopeProvider = new DependencyInjectionConsumerScopeProvider(provider);

            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #11
0
        /// <summary>
        /// Connect a consumer with a consumer factory method
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="kernel"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Consumer <TConsumer, TMessage>(this IBatchConfigurator <TMessage> configurator, IKernel kernel,
                                                          Action <IConsumerMessageConfigurator <TConsumer, Batch <TMessage> > > configure = null)
            where TConsumer : class, IConsumer <Batch <TMessage> >
            where TMessage : class
        {
            IConsumerScopeProvider scopeProvider = new WindsorConsumerScopeProvider(kernel);

            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
コード例 #12
0
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="context">The LifetimeScope of the container</param>
        /// <param name="name">The name of the scope created per-message</param>
        /// <returns></returns>
        public static void Consumer <T>(this IReceiveEndpointConfigurator configurator, IComponentContext context, string name = "message")
            where T : class, IConsumer
        {
            var lifetimeScope = context.Resolve <ILifetimeScope>();

            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(new SingleLifetimeScopeProvider(lifetimeScope), name);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory);
        }
コード例 #13
0
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <typeparam name="TId"></typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="context">The component context containing the registry</param>
        /// <param name="name">The name of the scope created per-message</param>
        /// <returns></returns>
        public static void ConsumerInScope <T, TId>(this IReceiveEndpointConfigurator configurator, IComponentContext context, string name = "message")
            where T : class, IConsumer
        {
            ILifetimeScopeRegistry <TId> registry = context.Resolve <ILifetimeScopeRegistry <TId> >();

            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(new RegistryLifetimeScopeProvider <TId>(registry), name);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory);
        }
コード例 #14
0
        /// <summary>
        /// Connect a consumer with a consumer factory method
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="scope"></param>
        /// <param name="configure"></param>
        /// <param name="name">The name of the scope created per-message</param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void Consumer <TConsumer, TMessage>(this IBatchConfigurator <TMessage> configurator, ILifetimeScope scope,
                                                          Action <IConsumerMessageConfigurator <TConsumer, Batch <TMessage> > > configure = null, string name = "message",
                                                          Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where TConsumer : class, IConsumer <Batch <TMessage> >
            where TMessage : class
        {
            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(new SingleLifetimeScopeProvider(scope), name, configureScope);

            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            configurator.Consumer(consumerFactory, configure);
        }
        /// <summary>
        /// Connect a consumer to the bus/mediator
        /// </summary>
        /// <typeparam name="TConsumer"></typeparam>
        /// <param name="connector"></param>
        /// <param name="provider"></param>
        /// <param name="pipeSpecifications"></param>
        /// <returns></returns>
        public static ConnectHandle ConnectConsumer <TConsumer>(this IConsumePipeConnector connector, IServiceProvider provider,
                                                                params IPipeSpecification <ConsumerConsumeContext <TConsumer> >[] pipeSpecifications)
            where TConsumer : class, IConsumer
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            IConsumerScopeProvider scopeProvider = new DependencyInjectionConsumerScopeProvider(provider);

            IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider);

            return(connector.ConnectConsumer(consumerFactory, pipeSpecifications));
        }
コード例 #16
0
        void IConsumerRegistration.Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider)
        {
            var scopeProvider        = configurationServiceProvider.GetRequiredService <IConsumerScopeProvider>();
            var consumerFactory      = new ScopeConsumerFactory <TConsumer>(scopeProvider);
            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            GetConsumerDefinition(configurationServiceProvider)
            .Configure(configurator, consumerConfigurator);

            foreach (Action <IConsumerConfigurator <TConsumer> > action in _configureActions)
            {
                action(consumerConfigurator);
            }

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
コード例 #17
0
        void IConsumerRegistration.Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider)
        {
            var scopeProvider        = configurationServiceProvider.GetRequiredService <IConsumerScopeProvider>();
            var consumerFactory      = new ScopeConsumerFactory <TConsumer>(scopeProvider);
            var consumerConfigurator = new ConsumerConfigurator <TConsumer>(consumerFactory, configurator);

            LogContext.Debug?.Log("Configuring endpoint {Endpoint}, Consumer: {ConsumerType}", configurator.InputAddress.GetLastPart(),
                                  TypeMetadataCache <TConsumer> .ShortName);

            GetConsumerDefinition(configurationServiceProvider)
            .Configure(configurator, consumerConfigurator);

            foreach (Action <IConsumerConfigurator <TConsumer> > action in _configureActions)
            {
                action(consumerConfigurator);
            }

            configurator.AddEndpointSpecification(consumerConfigurator);
        }
コード例 #18
0
            public void Configure(IReceiveEndpointConfigurator configurator, IConsumerScopeProvider scopeProvider)
            {
                var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

                configurator.Consumer(consumerFactory);
            }