Refactoring the approach to find factories to avoid problems with lazy loading and imports