Add support for generic factories (incomplete).