Class AbstractConfigurationModule

java.lang.Object
com.google.inject.AbstractModule
org.somda.sdc.common.guice.AbstractConfigurationModule
All Implemented Interfaces:
com.google.inject.Module
Direct Known Subclasses:
DefaultCommonConfigModule

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.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> void
    bind(String name, com.google.inject.TypeLiteral<T> typeLiteral, T value)
    Binds a configuration key to a value from outside.
    <T> void
    bind(String name, Class<T> dataType, T value)
    Binds a configuration key to a value from outside.
    protected final void
    Processes the default configuration.
    protected void
    Implement this method to apply some custom configuration.
    protected abstract void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractConfigurationModule

      public AbstractConfigurationModule()
  • Method Details

    • 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.
    • bind

      public <T> void bind(String name, com.google.inject.TypeLiteral<T> typeLiteral, @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.
      typeLiteral - 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!