static Func <TMessage, Guid> GetCorrelationIdSelector(EventBinder <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 <CorrelatedBy <Guid> >())
            {
                Type genericType = typeof(Correlated <>).MakeGenericType(typeof(TSaga), typeof(TMessage), typeof(TMessage));

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

                return(correlated.CorrelationIdSelector);
            }

            return(x => NewId.NextGuid());
        }
Esempio n. 2
0
        public PropertySagaSubscriptionConnector(ISagaRepository <TSaga> sagaRepository,
                                                 DataEvent <TSaga, TMessage> dataEvent,
                                                 IEnumerable <State> states,
                                                 ISagaPolicyFactory policyFactory,
                                                 Expression <Func <TSaga, bool> > removeExpression,
                                                 EventBinder <TSaga> eventBinder)
        {
            _sagaRepository = sagaRepository;
            _dataEvent      = dataEvent;

            _bindExpression = eventBinder.GetBindExpression <TMessage>();

            Func <TMessage, Guid> correlationIdSelector = GetCorrelationIdSelector(eventBinder);

            _policy = policyFactory.GetPolicy(states, correlationIdSelector, removeExpression);
        }
        public PropertyEventSagaWorkerConnector(ISagaRepository <TSaga> sagaRepository,
                                                DataEvent <TSaga, TMessage> dataEvent,
                                                IEnumerable <State> states,
                                                ISagaPolicyFactory policyFactory,
                                                Expression <Func <TSaga, bool> > removeExpression,
                                                EventBinder <TSaga> eventBinder)
            : base(sagaRepository)
        {
            _dataEvent        = dataEvent;
            _states           = states;
            _policyFactory    = policyFactory;
            _removeExpression = removeExpression;

            _bindExpression = eventBinder.GetBindExpression <TMessage>();

            _correlationIdSelector = GetCorrelationIdSelector(eventBinder);
        }