Move factory from config to Module class

Closures cannot be inserted into the module config file when these
files are cached, so remove the factory and put it inside the
Module class.