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

Feature Request: Composite Objects #72

Open
mmadson opened this issue Mar 6, 2014 · 1 comment
Open

Feature Request: Composite Objects #72

mmadson opened this issue Mar 6, 2014 · 1 comment

Comments

@mmadson
Copy link

mmadson commented Mar 6, 2014

Hi again,

This may be a bit outside the scope of what Owner should be able to do but I figured I'd throw it out there anyway.

@Config.Sources(...)
interface DbProperties extends Reloadable {

  @Key(...)
  String getJdbcUrl();

  @Key(...)
  String getJdbcUsername();

  @Key(...)
  String getJdbcPassword();

  @CompositePropertyProvider(DataSourceProvider.class)
  DataSource getDataSource()
}

class DataSourceProvider {
  DataSource create(properties) {
    return new DataSource(properties.getJdbcUrl()...);
  }
}
@lviggiano
Copy link
Collaborator

This looks very similar to what @ConverterClass is already doing.

But at the moment the instance of Converter cannot lookup on properties sources. When instantiating the Converter OWNER tries to invoke the default constructor. But, instead it could first try to see if a one-parameter constructor of type java.util.Properties is available, or if there is a one-parameter constructor accepting a subclass of org.aeonbits.Config, so that the ConverterClass can then access object properties as you are doing in your example in the DataSourceProvider.

I think this is a more convenient way than introducing a new annotation.

👍 Good suggestion.

@lviggiano lviggiano added this to the 1.0.6 milestone Mar 11, 2014
@lviggiano lviggiano self-assigned this Mar 11, 2014
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