من قبل
Zaid Rabab'a , Technical Team Lead , ESKADENIA Software
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.