public ISagaRegistrationConfigurator <T> AddSaga <T>(Type sagaDefinitionType, Action <ISagaConfigurator <T> > configure = null)
            where T : class, ISaga
        {
            if (typeof(T).HasInterface <SagaStateMachineInstance>())
            {
                throw new ArgumentException($"State machine sagas must be registered using AddSagaStateMachine: {TypeMetadataCache<T>.ShortName}");
            }

            ISagaRegistration ValueFactory(Type type)
            {
                SagaRegistrationCache.Register(type, Registrar);

                return(new SagaRegistration <T>());
            }

            var registration = _sagas.GetOrAdd(typeof(T), ValueFactory);

            registration.AddConfigureAction(configure);

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

            return(new SagaRegistrationConfigurator <T>(this, Registrar));
        }
        public void AddSaga(Type sagaType, Type sagaDefinitionType)
        {
            if (sagaType.HasInterface <SagaStateMachineInstance>())
            {
                throw new ArgumentException($"State machine sagas must be registered using AddSagaStateMachine: {TypeMetadataCache.GetShortName(sagaType)}");
            }

            _sagas.GetOrAdd(sagaType, type => SagaRegistrationCache.CreateRegistration(type, Registrar));

            if (sagaDefinitionType != null)
            {
                SagaDefinitionRegistrationCache.Register(sagaDefinitionType, Registrar);
            }
        }
Beispiel #3
0
        ISagaRegistrationConfigurator<T> IRegistrationConfigurator.AddSagaStateMachine<TStateMachine, T>(Type sagaDefinitionType)
        {
            ISagaRegistration Factory(IContainerRegistrar containerRegistrar)
            {
                SagaStateMachineRegistrationCache.Register(typeof(TStateMachine), containerRegistrar);

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

                return new SagaStateMachineRegistration<T>();
            }

            var registration = _sagaRegistrations.GetOrAdd(typeof(T), _ => Factory(_containerRegistrar));

            return new SagaRegistrationConfigurator<T>(this, registration, _containerRegistrar);
        }
        public ISagaRegistrationConfigurator <T> AddSagaStateMachine <TStateMachine, T>(Type sagaDefinitionType, Action <ISagaConfigurator <T> > configure = null)
            where TStateMachine : class, SagaStateMachine <T>
            where T : class, SagaStateMachineInstance
        {
            ISagaRegistration ValueFactory(Type type)
            {
                SagaStateMachineRegistrationCache.Register(typeof(TStateMachine), Registrar);

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

            var registration = _sagas.GetOrAdd(typeof(T), ValueFactory);

            registration.AddConfigureAction(configure);

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

            return(new SagaRegistrationConfigurator <T>(this, Registrar));
        }