org.allenai.common.guice

ConfigModule

Related Doc: package guice

class ConfigModule extends AbstractModule with ScalaModule with Logging

Parent class for modules which use a typesafe config for values. This automatically binds all configuration values within a given Config instance, along with defaults from an optional bundled config file. Each binding is annotated with @Named(configPath) to differentiate multiple bindings for a single primitive type.

This will bind config (HOCON) value types boolean, number, string, list, and object. Boolean and string entries are bound to the corresponding scala type. Numbers are bound to Double if they're floating point, and are bound to Int, Long, and Double if they're integral. Lists are bound to Seq[Config], since HOCON allows mixed list types. All object-valued keys are also bound as Config instances.

The default config filename is looked for in the implementing class's path, using the resource name module.conf. For example, if the implementing module is org.allenai.foobar.MyModule, module.conf should be in src/main/resources/org/allenai/foobar. defaultConfig provides the filename, if you want to change it from the default.

Example config and bindings:

Config file -

// format: OFF
stringValue = "foo"
someObject = {
  propNumber = 123
  propBool = true
}

Injected Scala class -

class Injected @Inject() (
  @Named("stringValue") foo: String,
  @Named("someObject.propBool") boolValue: Boolean,
  @Named("someObject.propNumber") integralValue: Int,
  someOtherParameter: ScalaClass,
  @Named("someObject.propNumber") numbersCanBeDoubles: Double
)
// format: ON
Linear Supertypes
Logging, ScalaModule, InternalModule[Binder], AbstractModule, Module, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. ConfigModule
  2. Logging
  3. ScalaModule
  4. InternalModule
  5. AbstractModule
  6. Module
  7. AnyRef
  8. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ConfigModule(config: com.typesafe.config.Config)

    config

    the runtime config to use containing all values to bind

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. def addError(arg0: Message): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  5. def addError(arg0: Throwable): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  6. def addError(arg0: String, arg1: <repeated...>[AnyRef]): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  7. def annotatedWith[A <: Annotation](implicit arg0: Manifest[A]): Matcher[AnnotatedElement]

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  8. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  9. def bind[T](implicit arg0: Manifest[T]): ScalaAnnotatedBindingBuilder[T] { ... /* 2 definitions in type refinement */ }

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  10. def bind[T](arg0: Class[T]): AnnotatedBindingBuilder[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  11. def bind[T](arg0: TypeLiteral[T]): AnnotatedBindingBuilder[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  12. def bind[T](arg0: Key[T]): LinkedBindingBuilder[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  13. def bindConstant(): AnnotatedConstantBindingBuilder

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  14. def bindInterceptor[I <: MethodInterceptor](classMatcher: Matcher[_ >: Class[_]], methodMatcher: Matcher[_ >: AnnotatedElement])(implicit arg0: Manifest[I]): Unit

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  15. def bindInterceptor(arg0: Matcher[_ >: Class[_]], arg1: Matcher[_ >: Method], arg2: <repeated...>[MethodInterceptor]): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  16. def bindListener(arg0: Matcher[_ >: Binding[_]], arg1: <repeated...>[ProvisionListener]): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  17. def bindListener(arg0: Matcher[_ >: TypeLiteral[_]], arg1: TypeListener): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  18. def bindScope[T <: Annotation](scope: Scope)(implicit arg0: Manifest[T]): Unit

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  19. def bindScope(arg0: Class[_ <: Annotation], arg1: Scope): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  20. def binder(): Binder

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  21. def binderAccess: Binder

    Attributes
    protected[this]
    Definition Classes
    ScalaModule → InternalModule
  22. def bindingPrefix: Option[String]

    If overridden, the namespace prefix that is prepended to all binding key names.

    If overridden, the namespace prefix that is prepended to all binding key names. This is used as a path prefix for all config values; so if the prefix is Some("foo") and the config key is "one.two", the final binding will be for @Named("foo.one.two").

    This is useful if you're providing a module within a library, and want to have your clients be able to pass Config overrides without having to worry about prefixing them properly.

  23. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. def configName: String

    The filename to use for the default.

    The filename to use for the default. Can be overridden for clarity.

  25. final def configure(): Unit

    Binds the config provided in the constructor, plus any default config found, and calls configureWithConfig with the resultant config object.

    Binds the config provided in the constructor, plus any default config found, and calls configureWithConfig with the resultant config object.

    Definition Classes
    ConfigModule → AbstractModule
  26. final def configure(arg0: Binder): Unit

    Definition Classes
    AbstractModule → Module
  27. def configureWithConfig(config: com.typesafe.config.Config): Unit

    Configure method for implementing classes to override if they wish to create additional bindings, or bindings based on config values.

    Configure method for implementing classes to override if they wish to create additional bindings, or bindings based on config values.

    config

    the fully-initilized config object

  28. def convertToTypes(arg0: Matcher[_ >: TypeLiteral[_]], arg1: TypeConverter): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  29. def currentStage(): Stage

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  30. def defaultConfig: com.typesafe.config.Config

    The config to use as a fallback.

    The config to use as a fallback. This is where keys will be looked up if they aren't present in the provided config.

  31. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  32. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  33. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  34. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  35. def getMembersInjector[T](implicit arg0: Manifest[T]): MembersInjector[T]

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  36. def getMembersInjector[T](arg0: TypeLiteral[T]): MembersInjector[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  37. def getMembersInjector[T](arg0: Class[T]): MembersInjector[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  38. def getProvider[T](implicit arg0: Manifest[T]): Provider[T]

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  39. def getProvider[T](arg0: Class[T]): Provider[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  40. def getProvider[T](arg0: Key[T]): Provider[T]

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  41. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  42. def install(arg0: Module): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  43. val internalLogger: Logger

    Definition Classes
    Logging
  44. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  45. object logger

    Definition Classes
    Logging
  46. object loggerConfig

    Simple logback configuration.

    Simple logback configuration. Hopefully this will be discoverable by just typing loggerConfig.[TAB]

    Examples: loggerConfig.Logger("org.apache.spark").setLevel(Level.WARN) loggerConfig.Logger().addAppender( loggerConfig.newPatternLayoutEncoder("%-5level [%thread]: %message%n"), loggerConfig.newConsoleAppender )

    Definition Classes
    Logging
  47. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  48. final def notify(): Unit

    Definition Classes
    AnyRef
  49. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  50. def requestInjection(arg0: Any): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  51. def requestStaticInjection[T]()(implicit arg0: Manifest[T]): Unit

    Attributes
    protected[this]
    Definition Classes
    InternalModule
  52. def requestStaticInjection(arg0: <repeated...>[Class[_]]): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  53. def requireBinding(arg0: Class[_]): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  54. def requireBinding(arg0: Key[_]): Unit

    Attributes
    protected[com.google.inject]
    Definition Classes
    AbstractModule
  55. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  56. def toString(): String

    Definition Classes
    AnyRef → Any
  57. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  58. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  59. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Logging

Inherited from ScalaModule

Inherited from InternalModule[Binder]

Inherited from AbstractModule

Inherited from Module

Inherited from AnyRef

Inherited from Any

Ungrouped