LiHan
Posted on June 13, 2023
Create Application
@HiltAndroidApp
class UserApplication : Application()
Add Name ... on AndroidManifest
<application
android:name=".UserApplication"
....
Add User Internet Permission
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Create UserModule.kt
這個檔案是為了提前產生物件.比如說:UserApi , UserRepostioryImpl
@Module
@InstallIn(SingletonComponent::class)
object UserModule {
@Provides
@Singleton
fun providesUserApi() : UserApi {
return Retrofit.Builder()
.baseUrl(UserApi.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build().create()
}
@Provides
@Singleton
fun providesUserRepository(
userApi : UserApi
) : UserRepository {
return UserRepositoryImpl(userApi)
}
}
💖 💪 🙅 🚩
LiHan
Posted on June 13, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.