static Func <TMessage, Guid> GetCorrelationIdSelector(IEventBinder <TSaga> binder)
        {
            Func <TMessage, Guid> correlationIdSelector = binder.GetCorrelationIdSelector <TMessage>();

            if (correlationIdSelector != null)
            {
                return(correlationIdSelector);
            }

            var visitor = new CorrelationExpressionToSagaIdVisitor <TSaga, TMessage>();

            Expression <Func <TMessage, Guid> > exp = visitor.Build(binder.GetBindExpression <TMessage>());

            if (exp != null)
            {
                return(exp.Compile());
            }

            if (typeof(TMessage).Implements <ICorrelatedBy <Guid> >())
            {
                Type genericType = typeof(Correlated <>).MakeGenericType(typeof(TSaga), typeof(TMessage), typeof(TMessage));

                var correlated = (ICorrelated <TMessage>)Activator.CreateInstance(genericType);

                return(correlated.CorrelationIdSelector);
            }

            return(x => NewIds.NewId.NextGuid());
        }
        static Func <TMessage, Guid> GenerateGetSagaIdFunction(Expression <Func <TSaga, TMessage, bool> > selector)
        {
            var visitor = new CorrelationExpressionToSagaIdVisitor <TSaga, TMessage>();

            Expression <Func <TMessage, Guid> > exp = visitor.Build(selector);

            return(exp != null?exp.Compile() : (x => CombGuid.Generate()));
        }
        static Func <TData, Guid> GenerateCorrelationIdSelector(Expression <Func <TInstance, TData, bool> > selector)
        {
            var visitor = new CorrelationExpressionToSagaIdVisitor <TInstance, TData>();

            Expression <Func <TData, Guid> > exp = visitor.Build(selector);

            return(exp != null?exp.Compile() : (x => NewId.NextGuid()));
        }
 public void Using_correlated_messages_to_start_sagas()
 {
     _builder = new CorrelationExpressionToSagaIdVisitor<SimpleSaga, InitiateSimpleSaga>();
 }
 public void Using_correlated_messages_to_start_sagas()
 {
     _builder = new CorrelationExpressionToSagaIdVisitor <SimpleSaga, InitiateSimpleSaga>();
 }