Phil Phil - 1 year ago 130
Scala Question

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

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] ("")

package somepackage

import com.typesafe.config.ConfigFactory
import scaldi._

class GlobalModule extends Module {


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?


Answer Source

The following should work for you:

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

val localValue = inject [String] ("")

Otherwise you can just append TypesafeConfigInjector(ConfigPath) to your module definition using :: operator (

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download