2

Is there a recommended way for injecting / accessing the application Typesafe config instance from within a Lagom service interface (ie, the trait, not Impl)?

The use case I am thinking of is for the creation of a request header filter that depends on a configurable value (like, an env specific secret) and injecting it via a constructor argument.

  final override def descriptor: Descriptor = {
    import Service._

    named("some-service")
      .withCalls(
        pathCall("/health", healthCheck),
      )
      .withHeaderFilter(new CustomerHeaderFilter(config))
  }

Unfortunately, from within the descriptor function, there is no readily exposed reference to the config. I have tried including as an abstract field on the service but this seems to cause Lagom to bomb out and complain that the field does not generate a service.

Is there a recommended way to do this or do I essentially have to call ConfigFactory.load()?

Currently using Lagom 1.4.5 + Scala - thanks!

simonl
  • 1,240
  • 7
  • 19
  • 1
    Best I know, Lagom services do not currently support DI. This should make sense, though, since an API shouldn't depend on configurations -- just implementations should be. – erip May 29 '18 at 01:17
  • If you are injecting a secret that's only used in the serving end (the actual lagom service implementation, not a client using the Service descriptor) I think you're better of not using Lagom's `HeaderFilter` and using Play webFilters instead. – ignasi35 May 30 '18 at 18:53

0 Answers0