public void ProcessMessage( MessageContext context, List <IMessageProcessor> processingChain, Action continueProcessing) { // if the chain is null or empty, complete processing if ((null == processingChain) || (!processingChain.Any())) { Log.Debug(string.Format("Message processing complete. Direction: {0}", context.Direction)); continueProcessing(); return; } // get the first processor IMessageProcessor processor = processingChain.First(); // create a processing chain that no longer contains this processor List <IMessageProcessor> newChain = processingChain.Skip(1).ToList(); // let it process the message and pass its "next" processor: a method that // recursively calls this function with the current processor removed Log.Debug(string.Format("Handing message to processor: {0} - Direction: {1}", processor.GetType(), context.Direction)); processor.ProcessMessage(context, () => ProcessMessage(context, newChain, continueProcessing)); }