implement method for defining factories and storing a generated factory