codelab-android-hilt icon indicating copy to clipboard operation
codelab-android-hilt copied to clipboard

Binds and scope annotations

Open nimbalabs opened this issue 3 years ago • 0 comments

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?

nimbalabs avatar Feb 08 '22 17:02 nimbalabs