-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Nested configuration interfaces (#129) #145
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Config
interface. If it is, thenany further conversion is handed off to
ConfigFactory
with a(configurable)namespace prefix.
@Source
annotationwill lookup the annotation on all interfaces.
Usage -