The use case I have is this:
An object requests a unbound @Named injection of a specific type. I want Guice to tell my ‘fallback’ provider what the name value was (or give me the entire annotation) so my provider can still provide an implementation based on the name value.
The @Named value is thus used as a key to find the correct implementation at runtime. If an implementation is found based on the @Named, then the provider should not be consulted.
Guice is basically a map from a (annotation, type) tuple to a
Provider<T>. There is no more a way to bind a default binding to all unbound@Namedinstances than there is to bind an entire range of doubles to a single string in aMap<Double, String>.If you have a convenient array or Collection of all
@Namedvalues you want, you could loop through them and bind them all to some kind of default provider, which you could then hack usingModules.override()or anifblock within the loop:If this is too complex for your taste, remember that you can always inject an instance of a one-method object that wraps the
Propertiesaccess for you, calculating a default if needed.