SingletonBinding

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

Annotation used to indicate that a class should be bound to a Singleton scope using Hilt. This annotation should be used on the implementation class and not on the interface.

Example usage:

@SingletonBinding
class FooImpl : Foo
interface Foo

This will generate the following Hilt module:

@Module
@InstallIn(SingletonComponent::class)
@OriginatingElement(
topLevelClass = FooImpl::class
)
interface FooImplModule {
@Binds
@Singleton
fun bindFoo(
fooImpl: FooImpl
): Foo
}

Properties

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.