If you're using a properties file and want to bind the configuration
options individually, you could use Names.bind and then provide
TypeConverters to convert between the string value and the target
type.

http://google-guice.googlecode.com/git/javadoc/com/google/inject/name/Names.html
http://google-guice.googlecode.com/git/javadoc/com/google/inject/spi/TypeConverter.html

Dan.

On Nov 16, 10:02 pm, Rich <[email protected]> wrote:
> I'm working on a small class that will read in a Map<String,Object>
> holding user preferences from a file.  I would like each of these
> entries to be injectable, so I'm looking at essentially:
>
> (Pseudocode)
> Map<String,Object> prefs = blah...
>
> for(Map.Entries e : prefs.entrySet) {
>    String key = e.getKey();
>    Object val = e.getValue();
>
>    binder.bind(value.getClass())
>           .annotatedWith(Names.named(key))
>           .toInstance(val);
>
> As you can imagine, things aren't working :-)
>
> TypeLiteral<> doesn't seem like a solution because I won't know the
> types of "val" until runtime.
>
> Is there any provision to support this specific thing?

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to