Michael Long
1 min readJul 3, 2019

--

If you were to check out the documentation for Resolver you’d see that there are several ways to perform injection on view controllers. It just so happens that, as mentioned, Service Locator was the easiest method to demonstrate in a short article, though Resolver also supports method injection.

View controllers are problematic in that in classic UIKit development using storyboards and segues we typically have no control over view controller construction and initialization. Everything happens behind the scenes, and short of doing some extensive method swizzling on UIViewController there’s no real solution to the problem.

The injection of the fetcher and service into the view model are examples of classic constructor injection techniques.

And the @Injected syntax is very much a dependency injection technique. Just ask Google and Dagger 2.

Just add the annotation and the service automatically appears.

--

--

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)