HiltBinding
@Target(allowedTargets = [AnnotationTarget.CLASS] )
Annotation used to indicate that a class should be bound to a Hilt component.
Example usage:
@HiltBinding(
component = SingletonComponent::class,
scope = Singleton::class,
qualifier = DefaultRepository::class
)
class ExampleRepositoryImpl : ExampleRepository {
override suspend fun getData() = "data"
}
Content copied to clipboard
This will generate a Hilt module that binds ExampleRepositoryImpl to the Singleton scope using the SingletonComponent.
@Module
@InstallIn(SingletonComponent::class)
@OriginatingElement(
topLevelClass = ExampleRepositoryImpl::class
)
interface ExampleRepositoryImplModule {
@Binds
@DefaultRepository
@Singleton
fun bindExampleRepository(
exampleRepositoryImpl: ExampleRepositoryImpl
): ExampleRepository
}
Content copied to clipboard