public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector bus, SagaStateMachine <TInstance> stateMachine, ILifetimeScope scope)
            where TInstance : class, SagaStateMachineInstance
        {
            var connector = new StateMachineConnector <TInstance>(stateMachine);

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

            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="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, SagaStateMachine <TInstance> stateMachine,
                                                        ILifetimeScope scope, Action <ISagaConfigurator <TInstance> > configure = null)
            where TInstance : class, SagaStateMachineInstance
        {
            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);
        }
示例#3
0
        public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector bus, SagaStateMachine <TInstance> stateMachine, ILifetimeScope scope,
                                                                        string name = "message",
                                                                        Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where TInstance : class, SagaStateMachineInstance
        {
            var connector = new StateMachineConnector <TInstance>(stateMachine);

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

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

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

            return(connector.ConnectSaga(bus, sagaRepository, specification));
        }
        /// <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);
            }
        }
示例#5
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="stateMachine">The state machine</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, SagaStateMachine <TInstance> stateMachine,
                                                        IComponentContext context,
                                                        Action <ISagaConfigurator <TInstance> > configure = null,
                                                        string name = "message",
                                                        Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where TInstance : class, SagaStateMachineInstance
        {
            var scope = context.Resolve <ILifetimeScope>();

            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);
        }