News for hackers. Stuff that matters.
Re:You probably don't need a dependency injection framework by hayst4ck on Sunday May 25, 2025 @09:40PM (#44093116)
If you construct an object once, then what is the difference between that and a singleton?

The answer is scope. Singletons exist explicitly for the purpose of violating scoping for the convenience of not having to thread that dependency through constructors.

https://testing.googleblog.com/2008/08/root-cause-of-singlet...

Re:You probably don't need a dependency injection framework by almostdeadguy on Monday May 26, 2025 @09:00AM (#44097060)
Calling these "singletons" maybe created confusion here, I'm more talking about singleton in the sense of a value that is created once and shared (i.e. injecting a value as a "Singleton" via something like Guice). I'm not arguing that you need to have values in global scope, I'm arguing that parameterless constructors prevent you from using shared values (actually _unless_ you have singletons in global scope).