コード例 #1
0
        /// <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 StructureMapSagaStateMachineFactory(container);

            var repositoryFactory = new StructureMapStateMachineSagaRepositoryFactory(container);

            foreach (var sagaType in sagaTypes)
            {
                StateMachineSagaConfiguratorCache.Configure(sagaType, configurator, stateMachineFactory, repositoryFactory);
            }
        }
        public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector bus, SagaStateMachine <TInstance> stateMachine,
                                                                        IContainer container)
            where TInstance : class, SagaStateMachineInstance
        {
            var connector = new StateMachineConnector <TInstance>(stateMachine);

            ISagaRepositoryFactory repositoryFactory = new StructureMapStateMachineSagaRepositoryFactory(container);

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

            ISagaSpecification <TInstance> specification = connector.CreateSagaSpecification <TInstance>();

            return(connector.ConnectSaga(bus, sagaRepository, specification));
        }
        /// <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="stateMachine">The state machine</param>
        /// <param name="container">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, SagaStateMachine <TInstance> stateMachine,
                                                        IContainer container, Action <ISagaConfigurator <TInstance> > configure = null)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaRepositoryFactory repositoryFactory = new StructureMapStateMachineSagaRepositoryFactory(container);

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

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

            configure?.Invoke(stateMachineConfigurator);

            configurator.AddEndpointSpecification(stateMachineConfigurator);
        }