I am reading some code and have trouble understanding
import dagger.Component
import dagger.Module
import dagger.Provides
import javax.inject.Inject
class Sound(val noise: String)
class Dog @Inject constructor(val sound: Sound)
@Module
class DogModule() {
@Provides
fun provideWoWo(): Sound = Sound("wowo")
@Provides
fun provideDog(sound : Sound): Dog = Dog(sound)
}
@Component(modules = [ DogModule::class ])
interface AnimalComponent {
val dog: Dog
}
fun main() {
val component = DaggerAnimalComponent.create()
println("The dog has sound ${component.dog.sound.noise}.")
}
why class Sound(val noise: String)
without @Inject
?
I thought it would be
class Sound @Inject constructor(val noise: String)
since Sound
class instance is also created via dagger just like Dog
class instance