Colton Idle
07/21/2023, 3:34 PM@Singleton
or is putting it in SingletonComponent good enough?
@InstallIn(SingletonComponent::class)
@Module
class AppModule {
@Provides
fun provideMoshi(): Moshi {
return Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
}
}
Nicholas Doglio
07/21/2023, 3:38 PM@InstallIn(SingletonComponent::class)
will add everything in the module to the singleton components DI graph.
Annotating your @Provides
with @Singleton
will make Moshi a singleton within that DI graph.Hristijan
07/21/2023, 3:47 PM@Provides
additionally with @Singleton
too so that they live in the @Singleton
scope inside the SingletonComponent
Colton Idle
07/21/2023, 3:56 PM@Singleton