HiltBinding

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class HiltBinding(val component: KClass<*>, val scope: KClass<*> = Any::class, val qualifier: KClass<*> = Any::class, val named: String = "")

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"
}

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
}

Properties

Link copied to clipboard
val component: KClass<*>

The Hilt component to which the class should be bound.

Link copied to clipboard
val named: String

A string used to distinguish between multiple bindings of the same type.

Link copied to clipboard
val qualifier: KClass<*>

The qualifier used to distinguish between multiple bindings of the same type.

Link copied to clipboard
val scope: KClass<*>

The scope to which the class should be bound.