| All you've done is push the burden of constructing the dependency to whomever is calling an passing that dependency to __init__ Consistently applied, all construction gets pushed to the entry-point of the program. Congratulations, you've just discovered the so-called "composition root". Now that all construction is taking place at once, the order matters as you can't pass a dependency to its dependent until the dependency has been constructed. But it may have its own dependencies. So now there is a topological sorting problem. Turns out computers are really good at topological sorting. So, someone made the computer do it, and we call that a dependency injection container. Tada. |
I guess I just don't see the problem.
That solves itself naturally through normal programming. Some function takes A as argument? Well I obviously make that A first. A requires B to setup? Well obviously I make that first.
I don't need to "sort" anything, it just follows naturally from the types and constraints of the API.