Multibinds

Annotates abstract graph members that declare multibindings.

You can declare that a multibound set or map is bound by annotating an abstract graph member that returns the set or map you want to declare with @Multibinds.

You do not have to use @Multibinds for sets or maps that have at least one contribution, but you do have to declare them if they may be empty. Empty multibindings are an error by default, you must set allowEmpty to true to allow empty multibindings.

@DependencyGraph interface MyGraph {
@Multibinds aSet(): Set<Foo>
@Multibinds @MyQualifier aQualifiedSet(): Set<Foo>
@Multibinds aMap(): Map<String, Foo>
@Multibinds @MyQualifier aQualifiedMap(): Map<String, Foo>

@Provides
fun usesMultibindings(set: Set<Foo>, @MyQualifier map: Map<String, Foo>): Any {
return …
}
}

A given set or map multibinding can be declared any number of times without error. Metro implements these declarations to return the declared multibinding.

Properties

Link copied to clipboard
val allowEmpty: Boolean = false