Thread
#android-architecture
    Ofir Bar

    Ofir Bar

    2 years ago
    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:
    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

    Leo

    2 years ago
    dagger 🗡️
    Ianmedeiros

    Ianmedeiros

    2 years ago
    Hide it behind an interface and inject it trough construction injection in your data layer classes
    Ofir Bar

    Ofir Bar

    2 years ago
    can you please show a sample code? (Even pseudocode will be ok)@Ianmedeiros
    d

    dewildte

    2 years ago
    :google: