AliSoftware / Dip

Simple Swift Dependency container. Use protocols to resolve your dependencies and avoid singletons / sharedInstances!
MIT License
978 stars 75 forks source link

About SwiftUI #236

Closed KirillSaltykov closed 4 years ago

KirillSaltykov commented 4 years ago

Hello! How can I use this library with SwiftUI? With Storyboards I can use @Injected and register(storyboardType:), but what can I do, when using SwiftUI?

ilyapuchka commented 4 years ago

I didn't have a hands-on experience with SwiftUI yet but from what I've seen my best guess would be to use Dip via Environment somehow. I would advice against putting the whole container in the environment and instead declare the dependencies of your SwiftUI views explicitly and only use container under the hood to provide the actual instances for the dependencies. This will ensure that you don't directly depend on Dip in your views. Using @Injected of course goes against that for the sake of ergonomics, so using Environment only somehow and only use Dip to provide instances for the environment would be the direction I would explore.