public Instance RepositoryFor(SagaTypes sagaTypes)
 {
     //A good place if needing something like RavenDbSagaRepository
     //The ObjectDef returned here will be a class that implements ISagaRepository
     //InMemorySagaRepository is a good example of one to look at
     return(new ConfiguredInstance(typeof(SagaRepositorySample)));
 }
        public void use_matching_storage_to_build_the_repository()
        {
            var types = new SagaTypes
            {
                MessageType = GetType(),
                StateType   = typeof(MySagaState)
            };

            var storage1 = MockRepository.GenerateMock <ISagaStorage>();
            var storage2 = MockRepository.GenerateMock <ISagaStorage>();
            var storage3 = MockRepository.GenerateMock <ISagaStorage>();

            var settings = new TransportSettings();

            settings.SagaStorageProviders.Add(storage1);
            settings.SagaStorageProviders.Add(storage2);
            settings.SagaStorageProviders.Add(storage3);

            var def = new ObjectDef();

            storage3.Stub(x => x.RepositoryFor(types))
            .Return(def);

            StatefulSagaConvention.DetermineSagaRepositoryDef(settings, types)
            .ShouldBeTheSameAs(def);
        }
        public void saga_types_gives_an_empty_guid_func_if_correlation_id_does_not_exist()
        {
            var types = new SagaTypes
            {
                MessageType = GetType()
            };

            var func = types.ToCorrelationIdFunc().ShouldBeOfType<Func<SagaTypesTester, Guid>>();
            func(this).ShouldBe(Guid.Empty);
        }
        public static InMemorySagaRepository <TState, TMessage> Create()
        {
            var types = new SagaTypes
            {
                StateType   = typeof(TState),
                MessageType = typeof(TMessage)
            };

            return(new InMemorySagaRepository <TState, TMessage>((Func <TMessage, Guid>)types.ToCorrelationIdFunc(), (Func <TState, Guid>)types.ToSagaIdFunc(), new SagaStateCacheFactory()));
        }
Beispiel #5
0
        public void saga_types_gives_an_empty_guid_func_if_correlation_id_does_not_exist()
        {
            var types = new SagaTypes
            {
                MessageType = GetType()
            };

            var func = types.ToCorrelationIdFunc().ShouldBeOfType <Func <SagaTypesTester, Guid> >();

            func(this).ShouldBe(Guid.Empty);
        }
        public void no_registered_storage_and_matches_the_idiom_so_use_in_memory_cache()
        {
            var types = new SagaTypes
            {
                MessageType = typeof(SagaMessageOne),
                StateType   = typeof(MySagaState)
            };

            StatefulSagaConvention.DetermineSagaRepositoryDef(new TransportSettings(), types)
            .Type.ShouldEqual(typeof(InMemorySagaRepository <MySagaState, SagaMessageOne>));
        }
        public static ObjectDef DetermineSagaRepositoryDef(TransportSettings settings, SagaTypes sagaTypes)
        {
            var def = settings.SagaStorageProviders.FirstValue(x => x.RepositoryFor(sagaTypes))
                      ?? new InMemorySagaStorage().RepositoryFor(sagaTypes);

            if (def == null)
            {
                throw new SagaRepositoryUnresolvableException(sagaTypes);
            }

            return def;
        }
        public ObjectDef RepositoryFor(SagaTypes sagaTypes)
        {
            if (sagaTypes.StateType.GetProperty(SagaTypes.Id) == null)
            {
                return null;
            }

            var objectDef = new ObjectDef(typeof (InMemorySagaRepository<,>), sagaTypes.StateType, sagaTypes.MessageType);

            objectDef.DependencyByValue(typeof(Func<,>).MakeGenericType(sagaTypes.StateType, typeof(Guid)), sagaTypes.ToSagaIdFunc());
            objectDef.DependencyByValue(typeof(Func<,>).MakeGenericType(sagaTypes.MessageType, typeof(Guid)), sagaTypes.ToCorrelationIdFunc());

            return objectDef;
        }
        public Instance RepositoryFor(SagaTypes sagaTypes)
        {
            if (sagaTypes.StateType.GetProperty(SagaTypes.Id) == null)
            {
                return null;
            }

            var instance = new ConfiguredInstance(typeof (InMemorySagaRepository<,>), sagaTypes.StateType, sagaTypes.MessageType);
            instance.Dependencies.Add(typeof(Func<,>).MakeGenericType(sagaTypes.StateType, typeof(Guid)), sagaTypes.ToSagaIdFunc());
            instance.Dependencies.Add(typeof(Func<,>).MakeGenericType(sagaTypes.MessageType, typeof(Guid)), sagaTypes.ToCorrelationIdFunc());


            return instance;
        }
        public ObjectDef RepositoryFor(SagaTypes sagaTypes)
        {
            if (sagaTypes.StateType.GetProperty(SagaTypes.Id) == null)
            {
                return(null);
            }

            var objectDef = new ObjectDef(typeof(InMemorySagaRepository <,>), sagaTypes.StateType, sagaTypes.MessageType);

            objectDef.DependencyByValue(typeof(Func <,>).MakeGenericType(sagaTypes.StateType, typeof(Guid)), sagaTypes.ToSagaIdFunc());
            objectDef.DependencyByValue(typeof(Func <,>).MakeGenericType(sagaTypes.MessageType, typeof(Guid)), sagaTypes.ToCorrelationIdFunc());

            return(objectDef);
        }
        public Instance RepositoryFor(SagaTypes sagaTypes)
        {
            if (sagaTypes.StateType.GetProperty(SagaTypes.Id) == null)
            {
                return(null);
            }

            var instance = new ConfiguredInstance(typeof(InMemorySagaRepository <,>), sagaTypes.StateType, sagaTypes.MessageType);

            instance.Dependencies.Add(typeof(Func <,>).MakeGenericType(sagaTypes.StateType, typeof(Guid)), sagaTypes.ToSagaIdFunc());
            instance.Dependencies.Add(typeof(Func <,>).MakeGenericType(sagaTypes.MessageType, typeof(Guid)), sagaTypes.ToCorrelationIdFunc());


            return(instance);
        }
Beispiel #12
0
        public void saga_types_being_able_to_gimme_a_correlation_id_getter_from_the_message_type()
        {
            var types = new SagaTypes
            {
                MessageType = typeof(SagaMessageOne)
            };

            var func = types.ToCorrelationIdFunc().ShouldBeOfType<Func<SagaMessageOne, Guid>>();

            var message = new SagaMessageOne
            {
                CorrelationId = Guid.NewGuid()
            };

            func(message).ShouldBe(message.CorrelationId);
        }
Beispiel #13
0
        public void saga_types_being_able_to_gimme_a_correlation_id_getter_from_the_message_type()
        {
            var types = new SagaTypes
            {
                MessageType = typeof(SagaMessageOne)
            };

            var func = types.ToCorrelationIdFunc().ShouldBeOfType <Func <SagaMessageOne, Guid> >();

            var message = new SagaMessageOne
            {
                CorrelationId = Guid.NewGuid()
            };

            func(message).ShouldBe(message.CorrelationId);
        }
Beispiel #14
0
        public void saga_types_being_able_to_gimme_an_id_getter_for_the_state_object()
        {
            var types = new SagaTypes
            {
                MessageType = typeof(SagaMessageOne),
                StateType = typeof(MySagaState)
            };

            var func = types.ToSagaIdFunc().ShouldBeOfType<Func<MySagaState, Guid>>();

            var state = new MySagaState
            {
                Id = Guid.NewGuid()
            };

            func(state).ShouldBe(state.Id);
        }
Beispiel #15
0
        public void saga_types_being_able_to_gimme_an_id_getter_for_the_state_object()
        {
            var types = new SagaTypes
            {
                MessageType = typeof(SagaMessageOne),
                StateType   = typeof(MySagaState)
            };

            var func = types.ToSagaIdFunc().ShouldBeOfType <Func <MySagaState, Guid> >();

            var state = new MySagaState
            {
                Id = Guid.NewGuid()
            };

            func(state).ShouldBe(state.Id);
        }
 public Instance RepositoryFor(SagaTypes sagaTypes)
 {
     return new ConfiguredInstance(typeof(SpecialSagaRepository<,>), sagaTypes.StateType, sagaTypes.MessageType);
 }
Beispiel #17
0
 void ISagaConfigurationObserver.SagaConfigured <TSaga>(ISagaConfigurator <TSaga> configurator)
 {
     SagaTypes.Add(typeof(TSaga));
 }
 public ObjectDef RepositoryFor(SagaTypes sagaTypes)
 {
     return(new ObjectDef(typeof(SpecialSagaRepository <,>), sagaTypes.StateType, sagaTypes.MessageType));
 }
 public StatefulSagaNode(SagaTypes types)
 {
     _types = types;
 }
 public SagaRepositoryUnresolvableException(SagaTypes sagaTypes)
     : base("Unable to determine a saga repository for {0}.  Does the saga type have a property Id:Guid and the message type a property of CorrelationId:Guid?".ToFormat(sagaTypes))
 {
 }