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);
            }
        }
Example #2
0
        /// <summary>
        /// Subscribe a state machine saga to the endpoint
        /// </summary>
        /// <typeparam name="TInstance">The state machine instance type</typeparam>
        /// <param name="configurator"></param>
        /// <param name="scope">The Autofac Lifetime Container to resolve the repository</param>
        /// <param name="configure">Optionally configure the saga</param>
        /// <param name="name">The name to use for the scope created for each message</param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope,
                                                        Action <ISagaConfigurator <TInstance> > configure = null, string name = "message", Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaStateMachineFactory stateMachineFactory = new AutofacSagaStateMachineFactory(scope);

            SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>();

            StateMachineSaga(configurator, stateMachine, scope, configure, name, configureScope);
        }
Example #3
0
        public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, ILifetimeScope scope, string name = "message",
                                                                        Action <ContainerBuilder, ConsumeContext> configureScope           = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaStateMachineFactory stateMachineFactory = new AutofacSagaStateMachineFactory(scope);

            SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>();

            return(pipe.ConnectStateMachineSaga(stateMachine, scope, name, configureScope));
        }
        /// <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>
        public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IComponentContext context, string name = "message")
        {
            var scope = context.Resolve <ILifetimeScope>();

            IEnumerable <Type> sagaTypes = FindStateMachineSagaTypes(context);

            var stateMachineFactory = new AutofacSagaStateMachineFactory(scope);

            var scopeProvider     = new SingleLifetimeScopeProvider(scope);
            var repositoryFactory = new AutofacStateMachineSagaRepositoryFactory(scopeProvider, name);

            foreach (var sagaType in sagaTypes)
            {
                StateMachineSagaConfiguratorCache.Configure(sagaType, configurator, stateMachineFactory, repositoryFactory);
            }
        }
        /// <summary>
        /// Subscribe a state machine saga to the endpoint
        /// </summary>
        /// <typeparam name="TInstance">The state machine instance type</typeparam>
        /// <param name="configurator"></param>
        /// <param name="scope">The StructureMap Container to resolve the repository</param>
        /// <param name="configure">Optionally configure the saga</param>
        /// <returns></returns>
        public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, Action <ISagaConfigurator <TInstance> > configure = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaStateMachineFactory stateMachineFactory = new AutofacSagaStateMachineFactory(scope);

            var stateMachine = stateMachineFactory.CreateStateMachine <TInstance>();

            ISagaRepositoryFactory repositoryFactory = new AutofacStateMachineSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), "message");

            var sagaRepository = repositoryFactory.CreateSagaRepository <TInstance>();

            var stateMachineConfigurator = new StateMachineSagaConfigurator <TInstance>(stateMachine, sagaRepository, configurator);

            configure?.Invoke(stateMachineConfigurator);

            configurator.AddEndpointSpecification(stateMachineConfigurator);
        }
Example #6
0
        /// <summary>
        /// Subscribe a state machine saga to the endpoint
        /// </summary>
        /// <typeparam name="TInstance">The state machine instance type</typeparam>
        /// <param name="configurator"></param>
        /// <param name="context">The Autofac root container to resolve the repository</param>
        /// <param name="configure">Optionally configure the saga</param>
        /// <param name="name">The name to use for the scope created for each message</param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IComponentContext context, Action <ISagaConfigurator <TInstance> > configure = null,
                                                        string name = "message",
                                                        Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where TInstance : class, SagaStateMachineInstance
        {
            var scope = context.Resolve <ILifetimeScope>();

            ISagaStateMachineFactory stateMachineFactory = new AutofacSagaStateMachineFactory(scope);

            SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>();

            ISagaRepositoryFactory repositoryFactory = new AutofacStateMachineSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), name, configureScope);

            ISagaRepository <TInstance> sagaRepository = repositoryFactory.CreateSagaRepository <TInstance>();

            var stateMachineConfigurator = new StateMachineSagaConfigurator <TInstance>(stateMachine, sagaRepository, configurator);

            configure?.Invoke(stateMachineConfigurator);

            configurator.AddEndpointSpecification(stateMachineConfigurator);
        }