On Apr 22, 2013, at 3:59 AM, Tim Boudreau <[email protected]> wrote:

> I wrote a micro-framework for exactly that purpose - binding strings to 
> contents from properties files, on top of another micro-framework for loading 
> them without hard-coding paths (you can have system defaults in 
> /etc/myapp.properties overlaid with ~/myapp.properties overlaid with 
> ./myapp.properties and it takes care of binding them to @Named) - which might 
> be helpful:
> 
> https://github.com/timboudreau/giulius
> and the javadoc here:
> http://timboudreau.com/builds/job/giulius/lastSuccessfulBuild/artifact/giulius-settings/target/site/apidocs/index.html
> http://timboudreau.com/builds/job/giulius/lastSuccessfulBuild/artifact/giulius/target/site/apidocs/index.html
> 
> If you need values before the injector is created, you'll want to work 
> directly with a Settings object (like a Properties without mutator methods - 
> see the last javascript link), but you could just as easily write a Provider 
> that uses @Named to get the string and initializes it on first use.
> 
> -Tim

An alternate approach might be to bind your "Settings" object and use a 
@Provides method in your PersistenceModule, like so:

public class PersistenceModule extends AbstractModule {
 
    ...

    @Provides
    Db4OStuff getDb4O(Settings settings) {
        // use your settings
    }
}

Or, you could just define a PersistenceModule constructor that has a Settings 
parameter if that's the time at which it's most convenient to work with the 
Settings object.

If you do wish to refactor your config access code away from your existing 
Settings class, Tim's Giulius looks simple and lightweight, though I happen to 
prefer are more strongly typed approach, so I'm currently enjoying using 
https://github.com/brianm/config-magic. I wrote a tiny wrapper around that to 
make it easy to use with Guice and any commons-config configuration source: 
https://github.com/palominolabs/config-inject.

No shortage of options for configuration handling… :)

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


Reply via email to