com.google.inject.multibindings

Annotation Type ProvidesIntoMap



  • @Documented
    @Target(value=METHOD)
    @Retention(value=RUNTIME)
    public @interface ProvidesIntoMap
    Annotates methods of a Module to add items to a MapBinder. The method's return type, binding annotation and additional key annotation determines what Map this will contribute to. For example,
     @ProvidesIntoMap
     @StringMapKey("Foo")
     @Named("urls")
     Plugin provideFooUrl(FooManager fm) { return fm.getPlugin(); }
    
     @ProvidesIntoMap
     @StringMapKey("Bar")
     @Named("urls")
     Plugin provideBarUrl(BarManager bm) { return bm.getPlugin(); }
     
    will add two items to the @Named("urls") Map<String, Plugin> map. The key 'Foo' will map to the provideFooUrl method, and the key 'Bar' will map to the provideBarUrl method. The values are bound as providers and will be evaluated at injection time.

    Because the key is specified as an annotation, only Strings, Classes, enums, primitive types and annotation instances are supported as keys.

    Since:
    4.0
    Author:
    sameb@google.com (Sam Berlin)

Copyright © 2006–2018 Google, Inc.. All rights reserved.