Configuration in Lagom Scala Domain Case Classes


(Eric Zuo) #1

Hi Community,

I am currently working on a new project using Lagom with Scala DSL.

From the Lagom Example codes (online-auction), I find we can reference the config from the Akka system:

  val needExpiresDelay = system.settings.config
    .getDuration("needExpiresDelay", TimeUnit.MILLISECONDS)
    .milliseconds

And Play Framework provides api for configurations like:

import play.api.Configuration

class TencentCosService @Inject()(config: Configuration) {
  private lazy val region: String =
    config.underlying.getString("finobacci.tencent.cos.region")
  ...
}

While I am putting many business logic in the models, is it possible for me to reference some magic numbers from the configuration and then change it via Kubernetes config map?

my codes could be:


case class Provider(id: UUID,
                    mobile: Mobile,
                    propertyLimits: Map[UUID, Int],
                    currentServingNeeds: Set[UUID]) {
  // TODO Put this to configuration
  private val propertyRecommendationUpsideLimit = 3
  // TODO Put this to configuration
  private val propertyRecommendationDownSideLimit = 0

  def getPropertyLimit(propertyId: UUID) =
    propertyLimits.getOrElse(propertyId, propertyRecommendationDownSideLimit)

...
}