Example #1
0
        public static void LoadFrom(this IReceiveEndpointConfigurator configurator, IContainer container)
        {
            var scopeProvider = new StructureMapConsumerScopeProvider(container);

            IList <Type> concreteTypes = FindTypes <IConsumer>(container, x => !x.HasInterface <ISaga>());

            if (concreteTypes.Count > 0)
            {
                foreach (var concreteType in concreteTypes)
                {
                    ConsumerConfiguratorCache.Configure(concreteType, configurator, scopeProvider);
                }
            }

            var sagaRepositoryFactory = new StructureMapSagaRepositoryFactory(container);

            IList <Type> sagaTypes = FindTypes <ISaga>(container, x => true);

            if (sagaTypes.Count > 0)
            {
                foreach (var sagaType in sagaTypes)
                {
                    SagaConfiguratorCache.Configure(sagaType, configurator, sagaRepositoryFactory);
                }
            }
        }
        static ISagaRepository <TInstance> CreateSagaRepository <TInstance>(IContainer container)
            where TInstance : class, SagaStateMachineInstance
        {
            ISagaRepositoryFactory repositoryFactory = new StructureMapSagaRepositoryFactory(container);

            return(repositoryFactory.CreateSagaRepository <TInstance>(AddStateMachineActivityFactory));
        }
        /// <summary>
        /// Registers a saga using the container that has the repository resolved from the container
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="container"></param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static void Saga <T>(this IReceiveEndpointConfigurator configurator, IContainer container, Action <ISagaConfigurator <T> > configure = null)
            where T : class, ISaga
        {
            ISagaRepositoryFactory factory = new StructureMapSagaRepositoryFactory(container);

            ISagaRepository <T> sagaRepository = factory.CreateSagaRepository <T>();

            configurator.Saga(sagaRepository, configure);
        }