In Scaldi, I loaded my own typesafe config, how can I set Scaldi to make it available?

103 views Asked by At

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?
      }
    }
  }

}
1

There are 1 answers

0
Mironor On BEST ANSWER

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)