من قبل
Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
At first, this question makes me made some research about factory pattern, but as I see you can pass a factory via dependency injection, like you pass anything else.
Maybe the recursiveness confuse you. I don't know what else to say about implementing it -
maybe Muhammad Nabeel answer helps you.