News for hackers. Stuff that matters.
Re:Dependency injection is dynamic scoping in disguise by bluejekyll on Thursday October 31, 2019 @09:55AM (#21408762)
How do you test? One of the things you get with dependency injection is a method to replace dependencies with other objects specifically to do thing like unit testing with mocks or integration testing with objects that provide specific failure modes.

This is much harder to do when everything is a static.

Edit: some typos.

Re:Dependency injection is dynamic scoping in disguise by zubspace on Thursday October 31, 2019 @10:00AM (#21408831)
All fields in the Master class are interfaces. You simply assign Mock-Implementations in the testing scenario, once in a startup routine. Done.
Re:Dependency injection is dynamic scoping in disguise by tmk1108 on Thursday October 31, 2019 @10:27AM (#21409157)
How do you deal with parallel tests execution? Given that they are all static, you can't have multiple tests running at the same time setting up the mocks or they might overlap
Re:Dependency injection is dynamic scoping in disguise by zubspace on Thursday October 31, 2019 @10:51AM (#21409441)
You can add a static "InitTest" method somewhere which initializes the modules. Use a double checked locking pattern [1] in there to make sure, that you instantiate and assign the modules used for testing exactly once.

[1] https://en.wikipedia.org/wiki/Double-checked_locking