Config Injection

distage-config library parses typesafe-config into arbitrary case classes or sealed traits and makes them available for summoning as a class dependency.

To use it, add distage-config library:

libraryDependencies += Izumi.R.distage_config

or

libraryDependencies += "io.7mind.izumi" %% "distage-config" % "0.8.0"

If you’re not using sbt-izumi-deps plugin.

Write a config in HOCON format:

# resources/application.conf
program {
    config {
        different = true
    }
}

Add ConfigModule into your injector:

import distage.config._
import com.typesafe.config.ConfigFactory

val config = ConfigFactory.load()

val injector = Injector(new ConfigModule(AppConfig(config)))

Now you can automatically parse config entries into case classes and summon them from any class:

final case class Config(different: Boolean)

class ConfiguredTaglessProgram[F[_]](
  config: Config @ConfPath("program.config"),
  primaryProgram: TaglessProgram[F] @Id("primary"),
  differentProgram: TaglessProgram[F] @Id("different") ) {

    val program = if (config.different) differentProgram else primaryProgram
}

class ConfiguredTryProgram[F[_]: TagK: Monad] extends ModuleDef {
  make[ConfiguredProgram[F]]
  make[TaglessProgram[F]].named("primary")
  make[TaglessProgram[F]].named("different")
}