For hilt, do I need to mark my @Provides method wi...
# dagger
c
For hilt, do I need to mark my @Provides method with
@Singleton
or is putting it in SingletonComponent good enough?
Copy code
@InstallIn(SingletonComponent::class)
@Module
class AppModule {
  @Provides
  fun provideMoshi(): Moshi {
    return Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
  }
}
n
@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.
h
You must annotate the
@Provides
additionally with
@Singleton
too so that they live in the
@Singleton
scope inside the
SingletonComponent
c
Gotcha. I will add
@Singleton