Shared global environments

Hi guys!

I'd like to get some ideas, how could I use AppEnvironment properties in Sub-Environments.
For example, I would create a locationManager and use this instance in all of my other Environments. LocationManager is a struct, so if it changes, does not affect the AppEnvironment's locationManager.

struct AppEnvironment {
   var locationManager: LocationManager
}

struct UserEnvironment {
   var locationManager: LocationManager
}

It's only an example, I have the same issue with my session manager/sockets/ble management... I just want only one instance in the whole app from these.
Is there any technique, tricks, pullback, or any elegant solution?
(I don't want to use singletons...)

1 Like

We actually have a case study for this very thing :smile:

Take a look at SystemEnvironment towards the bottom of the file to show how to bundle up a bunch of dependencies that can be easily shared amongst multiple features.

1 Like

Ahh thanks, sorry I didn't see that! :sweat_smile::+1:

Terms of Service

Privacy Policy

Cookie Policy