android / codelab-android-hilt

Apache License 2.0
348 stars 184 forks source link

Binds and scope annotations #43

Open nimbalabs opened 2 years ago

nimbalabs commented 2 years ago

Code lab claims this

@Binds methods must have the scoping annotations if the type is scoped, so that's why the functions above are annotated with @Singleton and @ActivityScoped. If @Binds or @Provides are used as a binding for a type, the scoping annotations in the type are not used anymore, so you can go ahead and remove them from the different implementation classes.

However, scope annotations in type are being used and works as expected in 2.40. Was it just outdated?

@ActivityScoped
class AppNavigatorImpl @Inject constructor(private val activity: FragmentActivity) : AppNavigator {
...
}

@Module
@InstallIn(ActivityComponent::class)
interface NavigationModule {

    @Binds
    fun providesAppNavigator(appNavigatorImpl: AppNavigatorImpl): AppNavigator
}

Same instance of AppNavigatorImpl is injected in MainActivity and ButtonFragment (child of MainActivity). Is it just outdated documentation in code labs?