/// <summary>
        /// Load the consumer configuration from the specified Autofac LifetimeScope
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="scope">The LifetimeScope of the container</param>
        /// <param name="name">The name to use for the scope created for each message</param>
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, string name = "message")
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(scope);

            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(lifetimeScopeProvider, name);

            IList <Type> concreteTypes = FindTypes(scope, r => !r.HasInterface <ISaga>(), typeof(IConsumer));

            if (concreteTypes.Count > 0)
            {
                foreach (var concreteType in concreteTypes)
                {
                    ConsumerConfiguratorCache.Configure(concreteType, configurator, scopeProvider);
                }
            }

            var sagaRepositoryFactory = new AutofacSagaRepositoryFactory(lifetimeScopeProvider, name);

            IList <Type> sagaTypes = FindTypes(scope, x => true, typeof(ISaga));

            if (sagaTypes.Count > 0)
            {
                foreach (var sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, sagaRepositoryFactory);
                }
            }
        }
Esempio n. 2
0
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IUnityContainer container)
        {
            var scopeProvider = new UnityConsumerScopeProvider(container);

            IList <Type> concreteTypes = FindTypes <IConsumer>(container, x => !x.HasInterface <ISaga>());

            if (concreteTypes.Count > 0)
            {
                foreach (var concreteType in concreteTypes)
                {
                    ConsumerConfiguratorCache.Configure(concreteType, configurator, scopeProvider);
                }
            }

            var sagaRepositoryFactory = new UnitySagaRepositoryFactory(container);

            IList <Type> sagaTypes = FindTypes <ISaga>(container, x => true);

            if (sagaTypes.Count > 0)
            {
                foreach (var sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, sagaRepositoryFactory);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Specify that the service bus should load its subscribers from the container passed as an argument.
        /// </summary>
        /// <param name="configurator">The configurator the extension method works on.</param>
        /// <param name="container">The Windsor container.</param>
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IKernel container)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException("configurator");
            }
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            IList <Type> consumerTypes = FindTypes <IConsumer>(container, x => !x.HasInterface <ISaga>());

            if (consumerTypes.Count > 0)
            {
                foreach (Type type in consumerTypes)
                {
                    ConsumerConfiguratorCache.Configure(type, configurator, container);
                }
            }

            IList <Type> sagaTypes = FindTypes <ISaga>(container, x => true);

            if (sagaTypes.Count > 0)
            {
                foreach (Type sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, container);
                }
            }
        }
Esempio n. 4
0
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IServiceProvider services)
        {
            foreach (var consumer in ConsumerConfiguratorCache.GetConsumers())
            {
                ConsumerConfiguratorCache.Configure(consumer, configurator, services);
            }

            foreach (var saga in SagaConfiguratorCache.GetSagas())
            {
                SagaConfiguratorCache.Configure(saga, configurator, services);
            }
        }
Esempio n. 5
0
        private static void AddHandlers(this IServiceCollection services, IEnumerable <Assembly> assembliesToScan)
        {
            assembliesToScan = assembliesToScan as Assembly[] ?? assembliesToScan.ToArray();

            foreach (var type in assembliesToScan.SelectMany(a => a.ExportedTypes))
            {
                if (type.CanBeCastTo(typeof(ISaga)))
                {
                    services.AddScoped(type);
                    SagaConfiguratorCache.Cache(type);
                }
                else if (type.CanBeCastTo(typeof(IConsumer)))
                {
                    services.AddScoped(type);
                    ConsumerConfiguratorCache.Cache(type);
                }
            }
        }
        /// <summary>
        /// Specify that the service bus should load its subscribers from the container passed as an argument.
        /// </summary>
        /// <param name="configurator">The configurator the extension method works on.</param>
        /// <param name="kernel">The Ninject kernel.</param>
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IKernel kernel)
        {
            var consumerCache = kernel.TryGet <IConsumerRegistry>();

            if (consumerCache != null)
            {
                foreach (var cachedConfigurator in consumerCache.GetConfigurators())
                {
                    cachedConfigurator.Configure(configurator, kernel);
                }
            }
            else
            {
                IList <Type> consumerTypes = FindTypes <IConsumer>(kernel, x => !x.HasInterface <ISaga>());
                if (consumerTypes.Count > 0)
                {
                    foreach (Type type in consumerTypes)
                    {
                        ConsumerConfiguratorCache.Configure(type, configurator, kernel);
                    }
                }
            }

            var sagaCache = kernel.TryGet <ISagaRegistry>();

            if (sagaCache != null)
            {
                foreach (var cachedConfigurator in sagaCache.GetConfigurators())
                {
                    cachedConfigurator.Configure(configurator, kernel);
                }
            }
            else
            {
                IList <Type> sagaTypes = FindTypes <ISaga>(kernel, x => true);
                if (sagaTypes.Count > 0)
                {
                    foreach (Type sagaType in sagaTypes)
                    {
                        SagaConfiguratorCache.Configure(sagaType, configurator, kernel);
                    }
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Specify that the service bus should load its subscribers from the container passed as an argument.
        /// </summary>
        /// <param name="configurator">The configurator the extension method works on.</param>
        /// <param name="kernel">The Ninject kernel.</param>
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IKernel kernel)
        {
            IList <Type> consumerTypes = FindTypes <IConsumer>(kernel, x => !x.HasInterface <ISaga>());

            if (consumerTypes.Count > 0)
            {
                foreach (Type type in consumerTypes)
                {
                    ConsumerConfiguratorCache.Configure(type, configurator, kernel);
                }
            }

            IList <Type> sagaTypes = FindTypes <ISaga>(kernel, x => true);

            if (sagaTypes.Count > 0)
            {
                foreach (Type sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, kernel);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Specify that the service bus should load its subscribers from the container passed as an argument.
        /// </summary>
        /// <param name="configurator">The configurator the extension method works on.</param>
        /// <param name="container">The StructureMap container.</param>
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IContainer container)
        {
            IList <Type> concreteTypes = FindTypes <IConsumer>(container, x => !x.HasInterface <ISaga>());

            if (concreteTypes.Count > 0)
            {
                foreach (Type concreteType in concreteTypes)
                {
                    ConsumerConfiguratorCache.Configure(concreteType, configurator, container);
                }
            }

            IList <Type> sagaTypes = FindTypes <ISaga>(container, x => true);

            if (sagaTypes.Count > 0)
            {
                foreach (Type sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, container);
                }
            }
        }
Esempio n. 9
0
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, string name = "message",
                                    Action <ContainerBuilder, ConsumeContext> configureScope = null)
        {
            var registration = scope.ResolveOptional <IRegistration>();

            if (registration != null)
            {
                registration.ConfigureConsumers(configurator);
                registration.ConfigureSagas(configurator);

                return;
            }

            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(scope);

            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(lifetimeScopeProvider, name, configureScope);

            IList <Type> concreteTypes = FindTypes(scope, r => !r.HasInterface <ISaga>(), typeof(IConsumer));

            if (concreteTypes.Count > 0)
            {
                foreach (var concreteType in concreteTypes)
                {
                    ConsumerConfiguratorCache.Configure(concreteType, configurator, scopeProvider);
                }
            }

            var sagaRepositoryFactory = new AutofacSagaRepositoryFactory(lifetimeScopeProvider, name, configureScope);

            IList <Type> sagaTypes = FindTypes(scope, x => true, typeof(ISaga));

            if (sagaTypes.Count > 0)
            {
                foreach (var sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, sagaRepositoryFactory);
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Load the consumer configuration from the specified Autofac LifetimeScope
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="scope">The LifetimeScope of the container</param>
        /// <param name="name">The name to use for the scope created for each message</param>
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope,
                                    string name = "message")
        {
            IList <Type> concreteTypes = FindTypes <IConsumer>(scope, r => !r.HasInterface <ISaga>());

            if (concreteTypes.Count > 0)
            {
                foreach (var concreteType in concreteTypes)
                {
                    ConsumerConfiguratorCache.Configure(concreteType, configurator, scope, name);
                }
            }

            IList <Type> sagaTypes = FindTypes <ISaga>(scope, x => true);

            if (sagaTypes.Count > 0)
            {
                foreach (var sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, scope, name);
                }
            }
        }
Esempio n. 11
0
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IKernel kernel)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            if (kernel == null)
            {
                throw new ArgumentNullException(nameof(kernel));
            }

            IList <Type> consumerTypes = FindTypes <IConsumer>(kernel, x => !x.HasInterface <ISaga>());

            if (consumerTypes.Count > 0)
            {
                var scopeProvider = new WindsorConsumerScopeProvider(kernel);

                foreach (var type in consumerTypes)
                {
                    ConsumerConfiguratorCache.Configure(type, configurator, scopeProvider);
                }
            }

            IList <Type> sagaTypes = FindTypes <ISaga>(kernel, x => true);

            if (sagaTypes.Count > 0)
            {
                var repositoryFactory = new WindsorSagaRepositoryFactory(kernel);

                foreach (var sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, repositoryFactory);
                }
            }
        }
 /// <summary>
 /// Applies the consumer to the endpoint.
 /// </summary>
 /// <param name="busName"></param>
 /// <param name="endpointName"></param>
 /// <param name="configurator"></param>
 public void Apply(string busName, string endpointName, IReceiveEndpointConfigurator configurator)
 {
     SagaConfiguratorCache.Configure(definition.Type, configurator, context);
 }