https://kotlinlang.org logo
o

Ofir Bar

02/20/2020, 1:49 PM
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

Leo

02/20/2020, 6:49 PM
dagger 🗡️
👍 3
i

Ianmedeiros

02/20/2020, 8:04 PM
Hide it behind an interface and inject it trough construction injection in your data layer classes
o

Ofir Bar

02/20/2020, 9:28 PM
can you please show a sample code? (Even pseudocode will be ok) @Ianmedeiros
d

dewildte

02/24/2020, 11:22 AM
google
3 Views