0

我想从配置文件加载我自己的配置。加载配置后,我希望能够使用 Scaldi 注入配置值。这是我加载类型安全配置的代码。如何调整此代码以便我可以使用此模块并注入如下: 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?
      }
    }
  }

}
4

1 回答 1

1

以下内容应该适合您:

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

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

否则,您可以使用运算符(http://scaldi.org/learn/#injector-composition)附加TypesafeConfigInjector(ConfigPath)到您的模块定义::

于 2016-10-25T12:36:56.733 回答