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.

Do I have any other alternative with Guice ?
Which of these method would you chose in that case ?

Thanks for your help.
Regards,
Jonathan Dray


--~--~---------~--~----~------------~-------~--~----~
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