/// <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 SimpleInjector container.</param> /// <remarks>You should register your message consumers with AsyncScoped lifestyle.</remarks> public static void LoadFrom(this IReceiveEndpointConfigurator configurator, Container container) { var consumerScopeProvider = new SimpleInjectorConsumerScopeProvider(container); IList <Type> concreteTypes = FindTypes <IConsumer>(container, x => !x.HasInterface <ISaga>()); if (concreteTypes.Count > 0) { foreach (var concreteType in concreteTypes) { ConsumerConfiguratorCache.Configure(concreteType, configurator, consumerScopeProvider); } } var repositoryFactory = new SimpleInjectorSagaRepositoryFactory(container); IList <Type> sagaTypes = FindTypes <ISaga>(container, x => true); if (sagaTypes.Count > 0) { foreach (var sagaType in sagaTypes) { SagaConfiguratorCache.Configure(sagaType, configurator, repositoryFactory); } } }
public static void Consumer <TConsumer, TMessage>(this IBatchConfigurator <TMessage> configurator, Container container, Action <IConsumerMessageConfigurator <TConsumer, Batch <TMessage> > > configure = null) where TConsumer : class, IConsumer <Batch <TMessage> > where TMessage : class { IConsumerScopeProvider scopeProvider = new SimpleInjectorConsumerScopeProvider(container); IConsumerFactory <TConsumer> consumerFactory = new ScopeConsumerFactory <TConsumer>(scopeProvider); configurator.Consumer(consumerFactory, configure); }