Hey guys, how do you manage instances of Firebase ...
# android-architecture
o
Hey guys, how do you manage instances of Firebase Authentication/Firebase Storage? To use Firebase Authentication, I need an instance of
FirebaseAuth
and
StorageReference
(Firebase Storage). I can only get it from my MainActivity, like the below: `MainActivity.kt`:
Copy code
class UploadCertificationActivity : AppCompatActivity() {
    private val mViewModel: UploadCertificationViewModel by viewModel()
    private lateinit var mStorageReference : StorageReference
    private lateinit var mFirebaseAuth : FirebaseAuth

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_profile_upload_certification)

        mFirebaseAuth = FirebaseAuth.getInstance()
        mStorageReference = FirebaseStorage.getInstance().getReference(mFirebaseAuth.currentUser!!.uid)
    }
I’d love to hear how you pass that to your repository and manage that in your projects in general. Please assume I will use that same instance throughout the project. Since right now, I am issues Firebase storage calls directly from my Activity.
l
dagger 🗡️
👍 3
i
Hide it behind an interface and inject it trough construction injection in your data layer classes
o
can you please show a sample code? (Even pseudocode will be ok) @Ianmedeiros
d
google