private async Task PublishCommandsAsync(Saga saga) { var messages = saga.GetUndispatchedCommands().Select(command => { dynamic typeAwareCommand = command; //this cast is required to pass the correct Type to the Notify Method. Otherwise IEvent is used as the Type return((Task)_commandDispatcher.SendAsync(typeAwareCommand)); }); await Task.WhenAll(messages); saga.ClearUndispatchedCommands(); }