All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.zhengframework.configuration.ConfigurationModule Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
package com.github.zhengframework.configuration;

import static com.google.inject.name.Names.named;

import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.name.Names;

public class ConfigurationModule extends ConfigurationAwareModule {

  private void bindConfiguration(Binder binder, Configuration configuration) {
    binder = binder.skipSources(Names.class);
    for (String key : configuration.keySet()) {
      binder.bind(Key.get(String.class, named(key)))
          .toProvider(new ConfigurationValueProvider(configuration, key));
    }
  }

  @Override
  protected void configure() {
    Configuration configuration = getConfiguration();
    bind(Configuration.class).toInstance(configuration);
    bindConfiguration(binder(), configuration);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy