Package-level declarations

Types

Link copied to clipboard
abstract class AppScope

A simple common app-wide scope key that can be used with SingleIn.

Link copied to clipboard
annotation class Assisted(val value: String = "")

Annotates an assisted parameter in an injected class or function. An assisted parameter is one that is supplied at instantiation-time rather than from the dependency graph.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class AssistedFactory

Annotates an abstract class or interface used to create an instance of a type via an assisted Inject constructor.

Link copied to clipboard

Binds a given type as a type-assignable return type. This is commonly used to bind implementation types to supertypes or to bind them into multibindings.

Link copied to clipboard
annotation class BoundType<T : Any>

This annotation is used with ContributesBinding, ContributesIntoSet, and ContributesIntoMap to define a bound type. This is analogous to the bound type of a Binds-annotated declaration.

Link copied to clipboard
Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class ContributesBinding(val scope: KClass<*>, val replaces: Array<KClass<*>> = [], val boundType: BoundType<*> = BoundType<Nothing>())

Contributes a binding of the annotated type to the given scope as a boundType (if specified) or single declared supertype.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class ContributesIntoMap(val scope: KClass<*>, val replaces: Array<KClass<*>> = [], val boundType: BoundType<*> = BoundType<Nothing>())

Contributes an IntoMap binding of the annotated type to the given scope as a boundType (if specified) or single declared supertype. A MapKey must be declared either on the annotated class or on the boundType.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class ContributesIntoSet(val scope: KClass<*>, val replaces: Array<KClass<*>> = [], val boundType: BoundType<*> = BoundType<Nothing>())

Contributes an IntoSet binding of the annotated type to the given scope as a boundType (if specified) or single declared supertype.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class ContributesTo(val scope: KClass<*>, val replaces: Array<KClass<*>> = [])

Contributes the annotated interface to the given scope. This is only applicable to interfaces. The downstream merged graph of the same scope will extend this interface in its implementation.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class DependencyGraph(val scope: KClass<*> = Nothing::class, val additionalScopes: Array<KClass<*>> = [])

Declares the annotated type to be a dependency graph. Metro's compiler plugin will build, validate, and implement this graph at compile-time.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class ElementsIntoSet

The callable's return type is a Collection<T> and all values are contributed to the set. The Collection<T> produced from the accumulation of values will be immutable. An example use is to provide a default empty set binding, which is otherwise not possible using IntoSet.

Link copied to clipboard

A common Qualifier to indicate a binding is only for a specific scope. This is useful for bindings that exist in multiple scoped and you want to disambiguate them from each other.

Link copied to clipboard

This annotation is used to indicate that the annotated declaration expects to have its dependencies injected. This is applicable to multiple targets, the primary form being constructor injection.

Link copied to clipboard
Link copied to clipboard

The declaration's return type forms the type argument for the value of a Map<K, Provider<V>>, and the combination of the annotated key and the returned value is contributed to the map as a key/value pair. The Map<K, Provider<V>> produced from the accumulation of values will be immutable.

Link copied to clipboard

The declaration's return type forms the generic type argument of a Set<T>, and the returned value is contributed to the set. The object graph will pass dependencies to the method as parameters. The Set<T> produced from the accumulation of values will be immutable.

Link copied to clipboard
annotation class MapKey(val unwrapValue: Boolean = true)

Identifies annotation types that are used to associate keys with values returned by provider callables in order to compose a map.

Link copied to clipboard
fun interface MembersInjector<T : Any>

Injects dependencies into the properties and functions on instances of type T. Ignores the presence or absence of an injectable constructor.

Link copied to clipboard

Annotates abstract module methods that declare multibindings.

Link copied to clipboard
fun interface Provider<T : Any>

A simple class that produces instances of T.

Link copied to clipboard

This annotation is used on callable declarations in a class to provide instances of a given type to dependency graph. Any class or interface can define providers, but they will not be included unless they are or are a supertype of a DependencyGraph-annotated type.

Link copied to clipboard
annotation class Qualifier

A qualifier annotation can be used to qualify or otherwise disambiguate a type on a dependency graph. This is useful for primarily two situations:

Link copied to clipboard
annotation class Scope

Marks an annotated annotation class as a scope annotation.

Link copied to clipboard

A Scope that uses a given scope key value to indicate what scope the annotated type is a singleton in.

Link copied to clipboard

Functions

Link copied to clipboard
inline fun <T : Any> createGraph(): T

Creates a new parameter-less graph of type T. Note this is only applicable for graphs that have no creators (i.e. DependencyGraph.Factory).

Link copied to clipboard
inline fun <T : Any> createGraphFactory(): T

Creates a new instance of a @DependencyGraph.Factory-annotated class.

Link copied to clipboard
inline fun <T : Any> provider(crossinline provider: () -> T): Provider<T>

A helper function to create a new Provider wrapper around a given provider lambda.

Link copied to clipboard
fun <T : Any> providerOf(value: T): Provider<T>

Creates a Provider wrapper around the given value.