Fork me on GitHub

ComposedConfigurationAccessor

Dropwizard makes heavy use of the Configuration object. Unfortunately, its design makes writing configured Bundles difficult. Bundle writers need access to their custom configuration but can't impose a bundle-specific Configuration class. A common idiom is to create accessor interfaces that users of the bundle need to implement. This is cumbersome and clumsy.

Soabase's ComposedConfigurationAccessor provides an alternative whereby the application configuration object is searched for a field with the custom configuration type.

Usage

The application's configuration object should contain the custom configurations needed by Soabase or any other extensions. The custom configuration instances are accessed by calling ComposedConfigurationAccessor.access(). E.g.

public class AppConfig extends Configuration {
        ...
    public MyConfig myConfig = new MyConfig();
}

    ...

public void run(AppConfig configuration, Environment environment) throws Exception {
    MyConfig myConfig = ComposedConfigurationAccessor.access(configuration, environment, MyConfig.class);
}