Status: New
Owner: ----

New issue 545 by [email protected]: Improve the com.google.inject.name.Names properties resolution
http://code.google.com/p/google-guice/issues/detail?id=545

Loading Properties/Map works like a charm but I'm sure it could be improved (and users would appreciate) with few effort: what I'm proposing, and submitting in the attached patch, is enabling the Apache Ant style properties resolution without modifying the existing Guice APIs.

The already known scenario is: given a dynamic property

    JDBC.url=jdbc:mysql://${JDBC.host}:${JDBC.port}/${JDBC.schema}

and given the following set of fixed properties

    JDBC.host=localhost
    JDBC.port=3306
    JDBC.schema=guice

when requesting the injection of JDBC.url:

    @Inject
    @Named("JDBC.url")
    String url;

the set value will be

    System.out.println(url) ---> jdbc:mysql://localhost:3306/guice

That will be available just invoking

    com.google.inject.name.Names#bindProperties(Binder,Map<String, String>)
    com.google.inject.name.Names#bindProperties(Binder,Properties)

moreover it would be useful adding 2 shortcuts to bind java system properties :

    com.google.inject.name.Names#bindSystemProperties(Binder)

so users could reuse them as variables:

    os=${os.name}-${os.version} (${os.arch})

same thing for environment variables:

    com.google.inject.name.Names#bindEnvironmentProperties(Binder)

so

    username={USER}


Implementation notes: no external dependencies and no APIs modifications are needed, only 4 package private classes have been added

Attachments:
        NamesImprovements.patch  14.0 KB

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" 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-dev?hl=en.

Reply via email to