Nested configuration interfaces (#129)#145
Conversation
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 -
```properties
#/etc/app.properties
app.db.username =
app.db.password =
app.jetty.host =
app.jetty.port =
```
```java
@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? |
| namespace = "ns"; | ||
| } | ||
| imports.put(namespace, text); | ||
| Object result = ConfigFactory.create((Class<? extends Config>) targetType, imports); |
There was a problem hiding this comment.
The problem here, is that every time this call is done, a new object (a dynamic proxy) is created; but that's also consistent with the rest of the code. Maybe we can add a class level annotation that allows owner to use a cached instance (see org.aeonbits.owner.ConfigCache.java, http://owner.aeonbits.org/docs/singleton/)
|
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? |
1b8f02f to
cd3dc86
Compare
This is only an initial draft to get feedback (please don't shoot me :)
This works by doing 2 things -
implementation of the
Configinterface. If it is, thenany further conversion is handed off to
ConfigFactorywith a(configurable)namespace prefix.
@Sourceannotationwill lookup the annotation on all interfaces.
Usage -