owner icon indicating copy to clipboard operation
owner copied to clipboard

Nested configuration interfaces (#129)

Open ketan opened this issue 10 years ago • 4 comments

This is only an initial draft to get feedback (please don't shoot me :)

This works by doing 2 things -

  • a converter that checks if the target type is an implementation of the Config interface. If it is, then any further conversion is handed off to ConfigFactory with a (configurable)namespace prefix.
  • The properties manager, that looks up @Source annotation will lookup the annotation on all interfaces.

Usage -

app.db.username =
app.db.password =

app.jetty.host =
app.jetty.port =
@Config.Sources({"/etc/app.properties"})
public interface BaseConfig extends Accessible {
}

public interface AppConfig extends BaseConfig {
   @DefaultValue("app.db")
    Database db();

    @DefaultValue("app.jetty")
    Jetty jetty();
}

public interface Database extends Accessible {
    @Key("${ns}.username")
    String host();

    @Key("${ns}.password")
    String password();
}

public interface Jetty extends Accessible {
    @Key("${ns}.host")
    String host();

    @Key("${ns}.port")
    int port();
}

ketan avatar Oct 01 '15 11:10 ketan

Hi @ketan,

I like your pull request. Can you add some unit tests?

lviggiano avatar May 06 '16 14:05 lviggiano

I would like to see this feature get added as well, is there anything I can do to help?

AarjavP avatar May 23 '17 15:05 AarjavP

Unfortunately I've not had time to look at this PR, I don't think the situation will change anytime sokn., If someone wants to pick up this PR and make improvements, I'm happy...

ketan avatar May 24 '17 01:05 ketan

I might give it a go. What improvements were you thinking of?

shakedel avatar May 29 '17 17:05 shakedel