How we can apply Dependency injection without using a Framework when we have two UIViewControllers that are very deep in the hierarchy and they both need the same dependency that holds state and those two UIViewControllers they don't have a common parent.
Example:
VC1 -> VC2 -> VC3 -> VC4
VC5 -> VC6 -> VC7 -> VC8
let's sat that VC4 and VC8 they both need UserService
that holds the current user.
Note that we want to avoid Singleton.
Is there an elegant way to handle this kind of DI situations ?
After some research I found that some mention Abstract Factory
, Context interfaces
, Builder
, strategy pattern
But I could not find an example on how to apply that on iOS
from Dependency Injection with swift with dependency graph of two UIViewControllers without common parent
No comments:
Post a Comment