Part of the solution would be looking at Names.bindProperties(...):
http://tinyurl.com/4wl5ed and using @Inject(optional=true).

The other part (naming convention) would require a custom injection
mechanism, potentially solved with Guice 2.0 constructor interception
(recently discussed on the mailing list). BUT if your properties all reside
in a single class, you could also not use Guice and use reflection to set a
bunch of properties, and then bind that instance using toInstance.

Robbie

On Sun, Oct 5, 2008 at 3:55 PM, AZ <[EMAIL PROTECTED]> wrote:

>
> I need to pull config options for beans (strings and ints and the
> like) from a file before bootstrapping and then push these config
> settings into the beans as they are starting up (replacing existing
> settings if needed). I just wanted to see if anyone else has done this
> already and has any suggestions.
>
> I am trying to do it like this:
> bindConstant().annotatedWith(Names.named(key)).to(value);
>
> This is sorta getting me what I want but not completely. There are 3
> issues I have not figured out that I am hoping someone else has:
> 1) I know exactly which bean the key and value should go with (if it
> exists, if not then this is ok and I will skip it) so I want to be
> able specify that so that I don't set the value on some other bean
> which happened to use the same key for a name.
> 2) I would prefer not to deal with names at all. The name of the
> setter method is fine here (sans "set") so I would prefer to simply be
> able to use that without requiring the annotation. In the case of
> constructors I want it to be able to use the Named annotation but
> without changing the vaue for all beans that use the same name (like
> #1).
> 3) I don't want things to fail if the constant is invalid. That has
> not really been a problem with the current approach because if the
> named constant is unused then things are ok but if I say "for bean A
> set value to B for field C" I want it to happily say "no field C" and
> keep going.
>
> I suppose this may all be easy if there is a way to put in an
> interceptor which is triggered when each bean is being created so
> maybe I just need to know how to do that.
> Thanks for any advice
> -AZ
>
> >
>

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