Top-level question: how do you expect the binding code to know what type to use for each entry in the file?
In a simple solution, you could predefine the types that are available to bind within code, and then use a meta entry in the file for each value you want to bind. You could also have inference logic in your binding code, but that depends on how limited the set of possible types are. That seems like the hardest thing to do, and then the binding would be simple afterwards. On Wed, Nov 16, 2011 at 5: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. > > -- 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.
