public static TriggerConfigurer FromMessage <TStateMachine, TMessage, TMessageContext>( this TriggerConfigurer configurer, Func <TMessage, TMessageContext, Guid> correlationFunc, Func <TStateMachine, TMessage, TMessageContext, Task> machineFunc, Action <IConsumerConfigurationBuilder> consumeConfig = null ) { Func <object[], Task <Acknowledgement> > genericHandler = args => machineFunc((TStateMachine)args[0], (TMessage)args[1], (TMessageContext)args[2]) .ContinueWith <Acknowledgement>(t => new Ack()); Func <object, object, Guid> genericCorrFunc = (msg, ctx) => correlationFunc((TMessage)msg, (TMessageContext)ctx); return(configurer.From(SubscribePipe, context => { var stateMachineContext = new StateMachineContext(context); stateMachineContext.Properties.Add(StateMachineKey.Type, typeof(TStateMachine)); stateMachineContext.AddMessageContextType <TMessageContext>(); stateMachineContext.Properties.Add(StateMachineKey.CorrelationFunc, genericCorrFunc); stateMachineContext.UseLazyCorrelationArgs(ctx => new[] { ctx.GetMessage(), ctx.GetMessageContext() }); stateMachineContext.Properties.Add(PipeKey.MessageType, typeof(TMessage)); stateMachineContext.Properties.Add(PipeKey.ConfigurationAction, consumeConfig); stateMachineContext.Properties.Add(PipeKey.MessageHandler, genericHandler); stateMachineContext.UseLazyHandlerArgs(ctx => new[] { ctx.GetStateMachine(), ctx.GetMessage(), ctx.GetMessageContext() }); })); }