Esempio n. 1
0
        private void StartSagaInstance <TPayload>(TPayload payload, Func <TPayload, TKey> getKey, Func <TPayload, TState> createState, Action <ISagaContext <TState, TKey> > onReceive)
        {
            var key   = getKey(payload);
            var state = createState(payload);

            if (state == null)
            {
                return;
            }
            var context = new SagaContext <TState, TKey>()
            {
                State = state,
                Key   = key
            };
            bool ok = _repository.SaveNew(key, context);

            if (!ok)
            {
                return;
            }

            onReceive?.Invoke(context);
            CheckStateCompletion(context, key, state);
        }