Install the module in `SingletonComponent` and scope the provider with `@Singleton`: ```kotlin @Module @InstallIn(SingletonComponent::class) object NetworkModule { @Provides @Singleton fun provideRetrofit(): Retrofit = Retrofit.Builder() .baseUrl("https://api.example.com/") .addConverterFactory(MoshiConverterFactory.create()) .build() @Provides @Singleton fun provideApi(retrofit: Retrofit): ProductApi = retrofit.create(ProductApi::class.java) } ``` Annotate the application with `@HiltAndroidA...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill android-di --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Android Di?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-android-di-agent-skills-standard)More formats (shields.io, HTML) on the badges page.
# Singleton Retrofit with Hilt
Install the module in `SingletonComponent` and scope the provider with `@Singleton`:
```kotlin
@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun provideRetrofit(): Retrofit =
Retrofit.Builder()
.baseUrl("https://api.example.com/")
.addConverterFactory(MoshiConverterFactory.create())
.build()
@Provides
@Singleton
fun provideApi(retrofit: Retrofit): ProductApi =
retrofit.create(ProductApi::class.java)
}
```
Annotate the application with `@HiltAndroidApp`, and annotate Android entry points such as activities and fragments with `@AndroidEntryPoint`. Hilt then creates one `Retrofit` instance in the application-wide singleton component and reuses it wherever `Retrofit` or `ProductApi` is constructor-injected.
```kotlin
class ProductRepository @Inject constructor(
private val api: ProductApi
)
```
Use a distinct qualifier if the app needs multiple Retrofit instances or base URLs.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!