Search code examples
scalaplayframework-2.0typesafe-config

Access Play Configuration in Plain Scala Module


I have a Play app that I want to split into:

  • rest - Play module that holds the rest interface

  • services - plain Scala module that holds actors and external services clients (ex S3)

I want to create a S3Client object class, but when instantiating it I need to read the config values from application.conf. I can not use play.api.Play.current.configuration since this is not a play module.

Am I thinking this wrong? What would be the most elegant way to achieve what I want?


Solution

  • just use typesafe Config factory

       import com.typesafe.config.ConfigFactory
    
       val conf = ConfigFactory.load("/path/to/your/conf/file/application.conf")
    
       //init your object with the conf file.