【问题标题】:How to write Firebase's instance in Kotlin如何在 Kotlin 中编写 Firebase 的实例
【发布时间】:2022-08-03 21:14:36
【问题描述】:
@Module
@InstallIn(ViewModelComponent::class)
class HiltModule {

    @Provides
    fun provideAuthentication(): FirebaseAuth = Firebase.auth
}

现在我正在学习 Kotlin。 我想如果我想使用一个实例,我应该在下面做。

@Module
@InstallIn(ViewModelComponent::class)
class HiltModule {

    @Provides
    fun provideAuthentication(){
       FirebaseAuth = Firebase.auth()
    }
}

但这是不对的。为什么不使用 Firebase.auth(),使用 Firebase.auth 发出它的实例?

我还有一个问题。 为什么不在 fun provideAuthentication() 中使用 \"{}\",而只使用 \":\" 获取属性?

请教我。 谢谢你。

    标签: android firebase kotlin google-cloud-platform firebase-authentication


    【解决方案1】:

    在 Kotlin 中执行此操作的最简单方法是:

    @Provides
    fun provideFirebaseAuth() = Firebase.auth
    

    所以将被注入的对象将是FirebaseAuth 类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 2022-08-05
      相关资源
      最近更新 更多