Michael Long
Nov 20, 2024

--

Interesting, albeit barebones Di service. Users should note that as implemented DI only returns "singletons", or in other words, one and only one instance of the service per application execution.

That's fine for, say, common network services, but somewhat less suitable when you want to start creating view models or other services that require individual instances per view.

If I read it correctly, the current implementation also instantiates each and every service when registered at app launch.

That's fine for a handful of services, but problematic when that number grows to include larger or more complex entities, or ones rarely used but the application at all.

I'd suggest "registering" the instance with a factory closure or autoclosure (thunk) so instantiation can be delayed until needed.

--

--

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.

No responses yet