Reputation: 327
I am migrating from play 2.4.x
to play 2.5.8
While migrating I am getting a lot of deprecation related warning that I am trying to resolve. Once such error is method current in object Play is deprecated: This is a static reference to application, use DI instead
below is the object
object Foo{
def testURL= {
val test = Play.current.configuration.getString("test.url")
}
If I try to use config = Configuration.load()
I get the error overloaded method value load with alternatives:
(environment: play.api.Environment)play.api.Configuration (environment: play.api.Environment,devSettings: Map[String,AnyRef])play.api.Configuration cannot be applied to ()
I there a way to use the play.api.configuration
here ? I don't want to convert object into singleton class.
Upvotes: 2
Views: 578
Reputation: 8202
I'm basing this answer on this group post because it's about as good an answer as you'll get for this topic.
What you're trying to do is an anti-pattern, because something is an object it should not depend on external state. Technically, configuration is based on the state of a file on the filesystem, so it is state in that sense.
To do this cleanly, you should use a class.
Upvotes: 3