Exemplo n.º 1
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 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);
                }
            }
        }
Exemplo n.º 2
0
        static ISagaRepository <TInstance> CreateSagaRepository <TInstance>(Container container)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaRepositoryFactory repositoryFactory = new SimpleInjectorSagaRepositoryFactory(container);

            return(repositoryFactory.CreateSagaRepository <TInstance>(AddStateMachineActivityFactory));
        }
        public static void Saga <T>(this IReceiveEndpointConfigurator configurator, Container container, Action <ISagaConfigurator <T> > configure = null)
            where T : class, ISaga
        {
            ISagaRepositoryFactory factory = new SimpleInjectorSagaRepositoryFactory(container);

            ISagaRepository <T> sagaRepository = factory.CreateSagaRepository <T>();

            configurator.Saga(sagaRepository, configure);
        }