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)
}
}
Top comments (0)