Help migrating configuration reads to Play 2.7.0

Hi all,

I’ve created and maintained a small Scala lib about JWT support for some time except I moved away from Scala for years now (it’s sad, I know…). But now, users are asking me to update the lib to Play 2.7.0 and I’m having issue with how to read the Play application configuration with all that injection magic.

My solution so far was to access Play.maybeApplication.configuration inside a Scala object but looks like that’s no longer an option. Full code is here.

Anyone could help me / give me some pointer on how to migrate this code to make it Play 2.7.0 compliant?

Thanks in advance!

I don’t think you can make it work without changing the interface. You’ll need to explicitly accept an instance of com.typesafe.config.Config somehow.

Thanks. I’m fine changing the interface and having a breaking change if needed. Does it mean there is no way to inject the Config with dependency injection and I should ask users to provide it as a param of the functions or init the object during app bootstrap?

I’m not too familiar with Scala so I can’t really help you there.

Hey @pauldijou,

What you can do is have JwtSession as a class and not as an object:

import play.api.Configuration

class JwtSession @Inject()(configuration: Configuration) extends JwtJsonImplicits with JwtPlayImplicits

And now you use configuration. You won’t even need getConfigString and getConfigMillis anymore because with play.api.Configuration you can do configuration.get[String](key) and configuration.get[Duration](key).

Users can then inject JwtSession in controllers or anywhere it is needed:

class FooController @Inject()(jwtSession: JwtSession, controllerComponents: ControllerComponents) extends AbstractController(controllerComponents) { ... }


1 Like

Thanks a lot! The upgrade is happening right now and all your comments have been put to good use.