Difference between Scala Play Configuration.get and Configuration.underlying.get

378 views
Skip to first unread message

Tianhao Li

unread,
Mar 31, 2016, 9:02:00 AM3/31/16
to play-framework
Since migrated to Play 2.5.x, Play recommends using DI to do configuration instead of old
current.configuration

.


Looks like, 
configuration.underlying.getString

is recommended.

Also, getString is available directly to configuration as well. But the difference is just first one return a
String

and second one return
Option[String]


Could I ask are there any other differences about using underlying or not? and which is the recommended way of doing configuration?

Thanks.

Greg Methvin

unread,
Mar 31, 2016, 5:41:27 PM3/31/16
to play-framework
The underlying Config is the actual Typesafe Config object, and the play Configuration is a wrapper around that. The underlying getString method will throw an exception if the key isn't there, which is fine if you know for sure that key will exist (e.g. there's a value in reference.conf). If you are using Typesafe Config idiomatically, config keys should always have default values so you actually don't need the option.

I would still recommend using the Play Configuration API since it provides some nice helpers on top of Config. The API is likely to change in a future Play version to be more in line with the idiomatic usage though.

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/631e6a3a-a8bc-44a2-b9e2-8ea81e745a6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Senior Software Engineer

Reply all
Reply to author
Forward
0 new messages