0

I want to load my own config from a configuration file. After loading the config I want to be able to inject the config values using Scaldi. Here is the code where I load the typesafe config. How can I adjust this code so that I can use this module and inject like: val localValue = inject [String] ("property.name")

package somepackage

import java.io.File
import com.typesafe.config.ConfigFactory
import scaldi._

class GlobalModule extends Module {

  privateLoadConfig()

  private def privateLoadConfig() = {
    val c = System.getProperty("jumpmicro.config.path")
    val configPath = if (c == null) "jumpmicro.conf" else c
    if (configPath != null) {
      val f = new File(configPath)
      if (f.exists()) {
        val config = ConfigFactory.parseFile(f)
        // @todo What to do here?
      }
    }
  }

}
Phil
  • 46,436
  • 33
  • 110
  • 175

1 Answers1

1

The following should work for you:

implicit val inj = TypesafeConfigInjector(ConfigPath) // or config, both work 

val localValue = inject [String] ("property.name")

Otherwise you can just append TypesafeConfigInjector(ConfigPath) to your module definition using :: operator (http://scaldi.org/learn/#injector-composition)

Mironor
  • 1,157
  • 10
  • 25