Example #1
0
        /// <summary>
        /// Scans the lifetime scope and registers any state machines sagas which are found in the scope using the Autofac saga repository
        /// and the appropriate state machine saga repository under the hood.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="context"></param>
        /// <param name="name"></param>
        /// <param name="configureScope">Configuration for scope container</param>
        public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IComponentContext context, string name = "message",
                                                 Action <ContainerBuilder, ConsumeContext> configureScope = null)
        {
            var registration = context.ResolveOptional <IRegistration>();

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

                return;
            }

            var scope = context.Resolve <ILifetimeScope>();

            IEnumerable <Type> sagaTypes = FindStateMachineSagaTypes(context);

            var stateMachineFactory = new AutofacSagaStateMachineFactory(scope);

            var scopeProvider     = new SingleLifetimeScopeProvider(scope);
            var repositoryFactory = new AutofacSagaRepositoryFactory(scopeProvider, name, configureScope);
            var activityFactory   = new AutofacStateMachineActivityFactory();

            foreach (var sagaType in sagaTypes)
            {
                StateMachineSagaConfiguratorCache.Configure(sagaType, configurator, stateMachineFactory, repositoryFactory, activityFactory);
            }
        }
        /// <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);
                }
            }
        }
Example #3
0
        static ISagaRepository <TInstance> CreateSagaRepository <TInstance>(ILifetimeScope scope, string name,
                                                                            Action <ContainerBuilder, ConsumeContext> configureScope)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaRepositoryFactory repositoryFactory = new AutofacSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), name, configureScope);

            return(repositoryFactory.CreateSagaRepository <TInstance>(AddStateMachineActivityFactory));
        }
        static ISagaRepository <TInstance> ResolveSagaRepository <TInstance>(this ILifetimeScope scope, string name = "message",
                                                                             Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where TInstance : class, ISaga
        {
            ISagaRepositoryFactory repositoryFactory = new AutofacSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), name, configureScope);

            return(repositoryFactory.CreateSagaRepository <TInstance>());
        }
        /// <summary>
        /// Registers a saga using the container that has the repository resolved from the container
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="scope"></param>
        /// <param name="name"></param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void Saga <T>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, string name = "message",
                                    Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where T : class, ISaga
        {
            ISagaRepositoryFactory factory = new AutofacSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), name, configureScope);

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

            configurator.Saga(sagaRepository);
        }
Example #6
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);
                }
            }
        }