I'm curious what are the side effects of having a single instance of a Firebase product as opposed to reinitializing them as needed? What is the general rule of thumb? Is it generally better to have several or fewer instances? Why or why not?
In my latest round of refactoring my app, it occured to me I could create a singleton class containing a single instance of every firebase product. But I have a vague memory of reading somewhere that you should try to minimize the amount of instances as possible, particularly with the Auth instance. Is this true? This makes sense for Auth but I could see issues with the others, at least in my app's case (relatively high quantity of content fetched and displayed at a time including firestore docs and images).
import Firebase
class FBServiceProvider {
static let shared = FBServiceProvider()
private init() { }
let auth = Auth.auth()
let stg = Storage.storage()
let db = Firestore.firestore()
let fn = Functions.functions()
let rc = RemoteConfig.remoteConfig()
let msg = Messaging.messaging()
}