Multibinds
@Target(allowedTargets = [AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.PROPERTY_GETTER] )
Annotates abstract module methods that declare multibindings.
You can declare that a multibound set or map is bound by annotating an abstract module method 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.
@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 …
}
}
Content copied to clipboard
A given set or map multibinding can be declared any number of times without error. Dagger never implements or calls any @Multibinds
methods.