Michael Long
Apr 1, 2021

--

Enjoyed article but question: Why would using .defaultDependencies lead to runtime failures?

Also, as a general rule I'm not a great fan of constructor injection as it tends to expose the internal workings of your dependencies, especially when your dependencies have dependencies which have dependencies, etc..

The .defaultDependencies trick allows for simplified dependency injection while still keeping compiler safety and that's good.

I guess the biggest issue I have with the approach is all of the extra boilerplate that would occur if A depends on B & C, B depends on D & E, and--in this case--E needs a G and not an F.

But again, great article. I like reading about different approaches to DI as it's sort of a hobby of mine.

https://github.com/hmlongco/Resolver

--

--

Michael Long
Michael Long

Written by Michael Long

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.

Responses (1)