On Wed, Feb 18, 2009 at 11:25 AM, Jonathan Dray <[email protected]> wrote: > > Hi, > > I'm using Guice for DI in one of my projects. > I need to choose the right class to inject depending on the value of a > property read in a properties file. > Here is a small exemple of what I want to do : > > Class myFarm { > @Inject > public myFarm(Animal animal) { > } > } > > Now I want that the Animal injected here should be an instance of a > "Cow" or a "Goat" (which implements the Animal Interface) mapped from > the property "myAnimal" read in my application property file. > > > I thought about two solutions : > > 1. use a custom provider to get an animal which takes the value of the > property as a parameter. > 2. In the configure method of my Guice Module instance, read the > property and add a binding depending on the value.
I would use the second method. Dhanji. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
