/// <summary>
        /// Specify that the service bus should load the StateMachineSagas from the container passed as argument
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="container"></param>
        public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IKernel container)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }


            var registrationConfigurator = new RegistrationConfigurator();

            container.Register(Component.For <ISagaStateMachineFactory>().Instance(new WindsorSagaStateMachineFactory(container)));
            container.Register(Component.For <IStateMachineActivityFactory>().Instance(new WindsorStateMachineActivityFactory()));
            container.Register(Component.For <ISagaRepositoryFactory>().Instance(new WindsorSagaRepositoryFactory(container)));

            IEnumerable <Type> sagaTypes = FindStateMachineSagaTypes(container);

            foreach (var sagaType in sagaTypes)
            {
                SagaStateMachineRegistrationCache.AddSagaStateMachine(registrationConfigurator, sagaType);
            }

            var registration = registrationConfigurator.CreateRegistration(new WindsorConfigurationServiceProvider(container));

            registration.ConfigureSagas(configurator);
        }
示例#2
0
        /// <summary>
        /// Add the state machine sagas in the specified assembly to the service collection
        /// </summary>
        /// <param name="builder"></param>
        public static void RegisterSagaStateMachine <TStateMachine, TInstance>(this ContainerBuilder builder)
            where TStateMachine : class, SagaStateMachine <TInstance>
            where TInstance : class, SagaStateMachineInstance
        {
            var registrar = new AutofacSagaStateMachineRegistrar(builder);

            SagaStateMachineRegistrationCache.Register(typeof(TStateMachine), registrar);
        }
示例#3
0
        /// <summary>
        /// Add the state machine sagas in the specified assembly to the service collection
        /// </summary>
        /// <param name="collection"></param>
        public static void RegisterSagaStateMachine <TStateMachine, TInstance>(this IServiceCollection collection)
            where TStateMachine : class, SagaStateMachine <TInstance>
            where TInstance : class, SagaStateMachineInstance
        {
            var registrar = new DependencyInjectionSagaStateMachineRegistrar(collection);

            SagaStateMachineRegistrationCache.Register(typeof(TStateMachine), registrar);
        }
        public static void RegisterSagaStateMachines(this IContainerRegistrar registrar, params Type[] types)
        {
            foreach (var type in types)
            {
                if (!type.HasInterface(typeof(SagaStateMachine <>)))
                {
                    throw new ArgumentException($"The type is not a saga state machine: {TypeMetadataCache.GetShortName(type)}", nameof(types));
                }

                SagaStateMachineRegistrationCache.Register(type, registrar);
            }
        }
示例#5
0
        /// <summary>
        /// Adds SagaStateMachines to the registry, using the factory method, and updates the registrar prior to registering so that the default
        /// saga registrar isn't notified.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="registrar"></param>
        /// <param name="types">The state machine types to add</param>
        public static void AddSagaStateMachines(this IRegistrationConfigurator configurator, ISagaStateMachineRegistrar registrar, params Type[] types)
        {
            IEnumerable <Type> sagaTypes           = types.Where(x => x.HasInterface(typeof(SagaStateMachine <>)));
            IEnumerable <Type> sagaDefinitionTypes = types.Where(x => x.HasInterface(typeof(ISagaDefinition <>)));

            var sagas = from c in sagaTypes
                        join d in sagaDefinitionTypes on c.GetClosingArguments(typeof(SagaStateMachine <>)).Single()
                        equals d.GetClosingArguments(typeof(ISagaDefinition <>)).Single() into dc
                        from d in dc.DefaultIfEmpty()
                        select new { SagaType = c, DefinitionType = d };

            foreach (var saga in sagas)
            {
                SagaStateMachineRegistrationCache.AddSagaStateMachine(configurator, saga.SagaType, saga.DefinitionType, registrar);
            }
        }
示例#6
0
        /// <summary>
        /// Adds a SagaStateMachine to the registry, using the factory method, and updates the registrar prior to registering so that the default
        /// saga registrar isn't notified.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="registrar"></param>
        /// <param name="sagaDefinitionType"></param>
        /// <typeparam name="TStateMachine"></typeparam>
        /// <typeparam name="TInstance"></typeparam>
        public static ISagaRegistrationConfigurator <TInstance> AddSagaStateMachine <TStateMachine, TInstance>(this IRegistrationConfigurator configurator,
                                                                                                               ISagaStateMachineRegistrar registrar, Type sagaDefinitionType = null)
            where TStateMachine : class, SagaStateMachine <TInstance>
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaRegistration Factory(IContainerRegistrar containerRegistrar)
            {
                SagaStateMachineRegistrationCache.Register(typeof(TStateMachine), registrar);

                if (sagaDefinitionType != null)
                {
                    SagaDefinitionRegistrationCache.Register(sagaDefinitionType, containerRegistrar);
                }

                return(new SagaStateMachineRegistration <TInstance>());
            }

            return(configurator.AddSaga <TInstance>(Factory));
        }
示例#7
0
        /// <summary>
        /// Add the state machine sagas in the specified assembly to the service collection
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="type">The state machine saga type</param>
        public static void RegisterSagaStateMachine(this ContainerBuilder builder, Type type)
        {
            var registrar = new AutofacSagaStateMachineRegistrar(builder);

            SagaStateMachineRegistrationCache.Register(type, registrar);
        }
示例#8
0
        /// <summary>
        /// Add the state machine sagas in the specified assembly to the service collection
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="type">The state machine saga type</param>
        public static void RegisterSagaStateMachine(this IServiceCollection collection, Type type)
        {
            var registrar = new DependencyInjectionSagaStateMachineRegistrar(collection);

            SagaStateMachineRegistrationCache.Register(type, registrar);
        }