Пример #1
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="container">The Lamar Lifetime Container to resolve the repository</param>
        /// <param name="configure">Optionally configure the saga</param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IContainer container,
                                                        Action <ISagaConfigurator <TInstance> > configure = null, Action <ConsumeContext> configureScope = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaStateMachineFactory stateMachineFactory = new LamarSagaStateMachineFactory(container);

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

            StateMachineSaga(configurator, stateMachine, container, configure, configureScope);
        }
Пример #2
0
        public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector pipe, IContainer scope,
                                                                        Action <ConsumeContext> configureScope = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaStateMachineFactory stateMachineFactory = new LamarSagaStateMachineFactory(scope);

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

            return(pipe.ConnectStateMachineSaga(stateMachine, scope, configureScope));
        }
        /// <summary>
        /// Scans the lifetime scope and registers any state machines sagas which are found in the scope using the StructureMap saga repository
        /// and the appropriate state machine saga repository under the hood.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="container"></param>
        public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IContainer container)
        {
            IList <Type> sagaTypes = FindStateMachineSagaTypes(container);

            var stateMachineFactory = new LamarSagaStateMachineFactory(container);

            var repositoryFactory = new LamarStateMachineSagaRepositoryFactory(container);

            foreach (var sagaType in sagaTypes)
            {
                StateMachineSagaConfiguratorCache.Configure(sagaType, configurator, stateMachineFactory, repositoryFactory);
            }
        }
        public static void StateMachineSaga <TInstance>(this IReceiveEndpointConfigurator configurator, IContainer container, Action <ISagaConfigurator <TInstance> > configure = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaStateMachineFactory stateMachineFactory = new LamarSagaStateMachineFactory(container);

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

            ISagaRepositoryFactory repositoryFactory = new LamarStateMachineSagaRepositoryFactory(container);

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

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

            configure?.Invoke(stateMachineConfigurator);

            configurator.AddEndpointSpecification(stateMachineConfigurator);
        }