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


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

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 {