The reason the dependency injection discussions go on forever is because passing state around is so fundamental to how we compose software. Object oriented languages push you into using classes and functional languages use function arguments (and closures).
This hasn't evolved very much so pick your poison:
- Global variables (statics in C#)
- Constructor arguments
- Properties
- Function arguments
- Thread/Async locals
The decision about where to get state from will determine how easy it is to unit test that thing. You can hate unit testing all you want but it’s really effective to do it for lots of things.
Things that will ruin your ability to test if you don't mock them:
- Dates and Time
- Random number generation
- Scheduling
- Timers
You can follow @davidfowl.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.