コード例 #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);
            }
        }
コード例 #2
0
        /// <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);
                }
            }
        }
コード例 #3
0
        ICompensateActivityScopeProvider <TActivity, TLog> CreateCompensateActivityScopeProvider <TActivity, TLog>(IComponentContext context)
            where TActivity : class, ICompensateActivity <TLog>
            where TLog : class
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(context.Resolve <ILifetimeScope>());

            return(new AutofacCompensateActivityScopeProvider <TActivity, TLog>(lifetimeScopeProvider, "message"));
        }
コード例 #4
0
        IExecuteActivityScopeProvider <TActivity, TArguments> CreateExecuteActivityScopeProvider <TActivity, TArguments>(IComponentContext context)
            where TActivity : class, IExecuteActivity <TArguments>
            where TArguments : class
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(context.Resolve <ILifetimeScope>());

            return(new AutofacExecuteActivityScopeProvider <TActivity, TArguments>(lifetimeScopeProvider, "message"));
        }
コード例 #5
0
        public static void CompensateActivityHost <TActivity, TLog>(this IReceiveEndpointConfigurator configurator, ILifetimeScope lifetimeScope, string name = "message")
            where TActivity : class, CompensateActivity <TLog>
            where TLog : class
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(lifetimeScope);

            var compensateActivityScopeProvider = new AutofacCompensateActivityScopeProvider <TActivity, TLog>(lifetimeScopeProvider, name);

            var factory = new ScopeCompensateActivityFactory <TActivity, TLog>(compensateActivityScopeProvider);

            var specification = new CompensateActivityHostSpecification <TActivity, TLog>(factory);

            configurator.AddEndpointSpecification(specification);
        }
コード例 #6
0
        public static void ExecuteActivityHost <TActivity, TArguments>(this IReceiveEndpointConfigurator configurator, ILifetimeScope lifetimeScope, string name = "message")
            where TActivity : class, ExecuteActivity <TArguments>
            where TArguments : class
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(lifetimeScope);

            var executeActivityScopeProvider = new AutofacExecuteActivityScopeProvider <TActivity, TArguments>(lifetimeScopeProvider, name);

            var factory = new ScopeExecuteActivityFactory <TActivity, TArguments>(executeActivityScopeProvider);

            var specification = new ExecuteActivityHostSpecification <TActivity, TArguments>(factory);

            configurator.AddEndpointSpecification(specification);
        }
コード例 #7
0
        /// <summary>
        /// Use scoped filter for <see cref="SendContext{T}" />
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="filterType">Filter type</param>
        /// <param name="provider">Configuration service provider</param>
        public static void UseSendFilter(this ISendPipelineConfigurator configurator, Type filterType, IConfigurationServiceProvider provider)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var lifetimeScope = provider.GetRequiredService <ILifetimeScope>();
            ILifetimeScopeProvider lifetimeScopeProvider = new SingleLifetimeScopeProvider(lifetimeScope);

            configurator.UseSendFilter(filterType, lifetimeScopeProvider);
        }
コード例 #8
0
        /// <summary>
        /// Use scoped filter for <see cref="ConsumeContext{T}" />
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="filterType">Filter type</param>
        /// <param name="registration">Registration Context</param>
        public static void UseConsumeFilter(this IConsumePipeConfigurator configurator, Type filterType, IRegistration registration)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            var lifetimeScope = registration.GetRequiredService <ILifetimeScope>();
            ILifetimeScopeProvider lifetimeScopeProvider = new SingleLifetimeScopeProvider(lifetimeScope);

            configurator.UseConsumeFilter(filterType, lifetimeScopeProvider);
        }
コード例 #9
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>
        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);
            }
        }
コード例 #10
0
        public static void ExecuteActivityHost <TActivity, TArguments>(this IReceiveEndpointConfigurator configurator, Uri compensateAddress, ILifetimeScope lifetimeScope,
                                                                       string name = "message",
                                                                       Action <ContainerBuilder, ExecuteContext <TArguments> > configureScope = null)
            where TActivity : class, ExecuteActivity <TArguments>
            where TArguments : class
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(lifetimeScope);

            var executeActivityScopeProvider = new AutofacExecuteActivityScopeProvider <TActivity, TArguments>(lifetimeScopeProvider, name, configureScope);

            var factory = new ScopeExecuteActivityFactory <TActivity, TArguments>(executeActivityScopeProvider);

            var specification = new ExecuteActivityHostSpecification <TActivity, TArguments>(factory, compensateAddress);

            configurator.AddEndpointSpecification(specification);
        }
コード例 #11
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);
                }
            }
        }
コード例 #12
0
        ISagaRepositoryFactory CreateSagaRepositoryFactory(IComponentContext context)
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(context.Resolve <ILifetimeScope>());

            return(new AutofacSagaRepositoryFactory(lifetimeScopeProvider, ScopeName, _configureScope));
        }
コード例 #13
0
        IConsumerScopeProvider CreateConsumerScopeProvider(IComponentContext context)
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(context.Resolve <ILifetimeScope>());

            return(new AutofacConsumerScopeProvider(lifetimeScopeProvider, ScopeName, _configureScope));
        }
コード例 #14
0
        /// <summary>
        /// Creates the <see cref="IConsumerScopeProvider"/>.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        static IConsumerScopeProvider CreateConsumerScopeProvider(IComponentContext context)
        {
            var lifetimeScopeProvider = new SingleLifetimeScopeProvider(context.Resolve <ILifetimeScope>());

            return(new AutofacConsumerScopeProvider(lifetimeScopeProvider, "message", RegisterScope));
        }