a better way to config controller with encapsulate closure