/// <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); } } }
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); } } }
/// <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); } } }
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); } }
private static void LoadConsumersFrom <TBusType, TRoutingType>(this IReceiveEndpointConfigurator configurator, ILifetimeScope rootScope) where TBusType : class, IConsumerBusType where TRoutingType : class, IConsumerRountingType { try { foreach (var consumerType in rootScope.FindConsumerTypes <TBusType, TRoutingType>()) { var scopeProvider = new AutofacConsumerScopeProvider(new SingleLifetimeScopeProvider(rootScope), AutofacExtensions.ServiceBusMessageScopeTag); ConsumerConfiguratorCache.Configure(consumerType, configurator, scopeProvider); } } catch (Exception e) { Log.Error(e, $"Failed to register receive endpoint: {configurator.InputAddress}"); } }
/// <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); } } } }
private static void LoadConsumersFrom <TBusType, TRoutingType>( this IReceiveEndpointConfigurator configurator, IServiceProvider provider) where TBusType : class, IConsumerBusType where TRoutingType : class, IConsumerRountingType { try { foreach (var consumerType in provider.FindConsumerTypes <TBusType, TRoutingType>()) { var scopeProvider = provider.GetRequiredService <IConsumerScopeProvider>(); ConsumerConfiguratorCache.Configure(consumerType, configurator, scopeProvider); } } catch (Exception e) { Logger.LogError(e, $"Failed to register receive endpoint: {configurator.InputAddress}"); } }
/// <summary> /// Creates all configured receive endpoints using the specified host and service provider. /// </summary> /// <param name="host">The host.</param> /// <param name="provider">The provider.</param> /// <param name="configure">The configure.</param> public void CreateReceiveEndpoints(IRabbitMqHost host, IServiceProvider provider, IRabbitMqBusFactoryConfigurator configure) { foreach (var kvp in _receivers) { configure.ReceiveEndpoint(host, kvp.Key, c => { kvp.Value.ReceiveEndpointConfigurator?.Invoke(c); if (kvp.Value.RetryConfigurator != null) { c.UseRetry(kvp.Value.RetryConfigurator); } foreach (var type in kvp.Value.Types) { ConsumerConfiguratorCache.Configure(type, c, new DependencyInjectionConsumerScopeProvider (provider)); } }); } }
/// <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); } } }
/// <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); } } }
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); } } }
/// <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); } } }
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) { ConsumerConfiguratorCache.Configure(definition.Type, configurator, scopeProvider); }