owner
owner copied to clipboard
Nested configuration interfaces (#129)
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
Configinterface. If it is, then any further conversion is handed off toConfigFactorywith a (configurable)namespace prefix. - The properties manager, that looks up
@Sourceannotation 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();
}
Hi @ketan,
I like your pull request. Can you add some unit tests?
I would like to see this feature get added as well, is there anything I can do to help?
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...
I might give it a go. What improvements were you thinking of?