Martin Devillers
08/28/2019, 3:18 PMcedric
08/28/2019, 6:51 PMAs a general rule, singletons go against the principle of dependency injection,I don’t understand that. Singletons are perfect candidates for DI. What does it mean that they “go against the principle of DI”?
Martin Devillers
08/29/2019, 7:33 AMcedric
08/29/2019, 10:54 AMMartin Devillers
08/29/2019, 11:19 AMSingletonClass.getInstance()
, then I have a dependency on that singleton class, but I’m not injecting itcedric
08/29/2019, 11:20 AMMarko Mitic
08/29/2019, 11:26 AMMartin Devillers
08/29/2019, 11:37 AMMatteo Mirk
08/29/2019, 1:38 PMcedric
08/29/2019, 1:40 PMstreetsofboston
08/29/2019, 1:46 PMMarko Mitic
08/29/2019, 1:50 PMSingleton.getInstance()
- bad, breaks DI
singleton as constructor param - good, testablecedric
08/29/2019, 1:58 PMstatic
.Matteo Mirk
08/29/2019, 1:59 PMSingleton.getInstance()
is called inside the class — same applies for a regular object instantiation: that penalizes IoC and testabilitycedric
08/29/2019, 2:04 PMMatteo Mirk
08/29/2019, 2:19 PMstreetsofboston
08/29/2019, 2:30 PMDALDEI
09/01/2019, 9:52 PM