Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Prefix annotation on interfaces for keys #56

Open
binkley opened this issue Oct 12, 2013 · 7 comments
Open

@Prefix annotation on interfaces for keys #56

binkley opened this issue Oct 12, 2013 · 7 comments

Comments

@binkley
Copy link

binkley commented Oct 12, 2013

I'd rather write:

@Prefix("foo.bar")
interface Shorter extends Config {
    int a();
    String b();
}

Than:

interface Longer extends Config {
    @Key("foo.bar.a")
    int a();
    @Key("foo.bar.b")
    String b();
}

Especially as @key doesn't seem to like @key("${prefix}.baz"). (But please consider @Prefix first! Or @KeyPrefix!)

@lviggiano
Copy link
Collaborator

I like both, the @KeyPrefix and the variable expansion in the @Key annotation. And they should be easy to implement.

@ghost ghost assigned lviggiano Oct 12, 2013
@lviggiano
Copy link
Collaborator

In particular, consider a property file like this

# Production settings
prod.service.endpoint=http://productionserver:80

# Development settings
dev.service.endpoint=http://developmentserver:8080

# User acceptance test settings
uat.service.endpoint=http://testserver:8080

One could have a class like:

interface MyConfig extends Config {

    @Key("${environment}.service.endpoint")
    URL serviceEndpoint();

}

Where ${environment} can be passed from outside at creation time (ConfigFactory) or by System properties, to have a single file that configures different deployment environments. The variable expansion already works in the @sources and this can be implemented using different files, but also giving the user the chance to have a single properties file defining all the environments could be good, from the user perspective.

@binkley
Copy link
Author

binkley commented Oct 13, 2013

This fits my use case perfectly. Thanks!

@binkley
Copy link
Author

binkley commented Oct 13, 2013

@lviggiano
Copy link
Collaborator

Yes, very much :) I noticed it the other day.

@binkley
Copy link
Author

binkley commented Oct 28, 2013

Here's the kind of simple application I want to write, using OWNER API and
jopt-simple, glued with Guice:

https://github.com/binkley/binkley/blob/develop/guice/src/main/java/hm/binkley/inject/DemoMain.java

Cheers,
--binkley

On Sun, Oct 13, 2013 at 9:25 PM, Luigi R. Viggiano <[email protected]

wrote:

Yes, very much :) I noticed ithttps://twitter.com/lviggiano/status/388639933524504576the other day :)


Reply to this email directly or view it on GitHubhttps://github.com//issues/56#issuecomment-26215146
.

@lviggiano
Copy link
Collaborator

👍 (I'll work on this request asap: those day I started a new job contract, so I've been very busy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants