Michael Long
Dec 13, 2021

--

This idea has been bopping around for awhile, starting with an article by Antoine van Der Lee.

Your implementation is intriguing in how you solved the mock/testing problem, but a bit lacking in that given the current implementation all you've done is create an indirect path to a set of singletons.

IOW, every single injection is going to be a reference to the same exact instance of an object. Without some sort of factory mechanism there's no way to build new, fresh objects when needed.

Another drawback is, without factories, every object must be constructed and initialized at application launch. When you only have two of them, as shown here, that's not an issue, but it can quickly become one in a larger project.

You might take a look at the following demonstration project which attempts to resolve [sic] some of those issues.

https://github.com/hmlongco/InjectableDemo

--

--

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)