Class AbstractConfigurationModule

  • All Implemented Interfaces:
    com.google.inject.Module

    public abstract class AbstractConfigurationModule
    extends com.google.inject.AbstractModule
    Utility class for other modules to allow app configuration via Google Guice.

    Derive any concrete configuration module in order to override default values. Use bind(String, Class, Object) to set values.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      <T> void bind​(String name, Class<T> dataType, T value)
      Binds a configuration key to a value from outside.
      protected void configure()
      Processes the default configuration.
      protected void customConfigure()
      Implement this method to apply some custom configuration.
      protected abstract void defaultConfigure()
      Implement this method to settle your default configuration.
      • Methods inherited from class com.google.inject.AbstractModule

        addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBinding
    • Constructor Detail

      • AbstractConfigurationModule

        public AbstractConfigurationModule()
    • Method Detail

      • bind

        public <T> void bind​(String name,
                             Class<T> dataType,
                             @Nullable
                             T value)
        Binds a configuration key to a value from outside.

        This operation can only be performed once per key. All unpopulated keys are supposed to be filled with a default value once configure() is called by Guice.

        Type Parameters:
        T - type that is required by the given key.
        Parameters:
        name - the configuration key.
        dataType - the data type bound by the key (should be defined in configuration class).
        value - the configuration value to set.
      • configure

        protected final void configure()
        Processes the default configuration.

        This method is called by Guice to apply the configuration values.

        Overrides:
        configure in class com.google.inject.AbstractModule
      • defaultConfigure

        protected abstract void defaultConfigure()
        Implement this method to settle your default configuration.

        This is only relevant to the module that provides a certain configuration!

      • customConfigure

        protected void customConfigure()
        Implement this method to apply some custom configuration.

        This method is relevant to users that want to override default configuration values. Instead of overriding this function, it is also legit to bind values from outside the instance itself by using bind(String, Class, Object). Always to that before an instance is processed by Guice!