Use the output of a module inside a class (including task (generator)

Yes, uvm_config_db should be used to set from module and get in class. Config_db class is recommended.