Comment

Comment by ldlework

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.

parent ldlework 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton