Composing Service calls via mixins?


(Normen Müller) #1

Is there an option/ approach to compose service calls like

class MyServiceImpl(registry: PersistentEntityRegistry)(implicit ec: ExecutionContext) extends MyService {

  override val signup: ServiceCall[Signup, Done] =
    ServiceCall with Logging { request => ... }
//              ^^^^^^^^^^^^
}

(Ignasi Marimon-Clos) #2

Hi Normen,

not sure what Logging is in that snippet, but I the reason it doesn’t work is that ServiceCall{...} is actually invoking the object ServiceCall#apply(call: Request => Future[Response]) method and not creating an anonymous class.

I managed to make it work with a couple of changes

  override def hello(id: String) =
    new ServiceCall[NotUsed, String]  // here I'm creating an anon class from the ServiceCall trait
     with Logging {                               // and I mixing the kafka.utils.Logging trait.
        // because I'm extending the ServiceCall trait I have to 
        // implement the unimplemented methods.
        override def invoke(request: NotUsed): Future[String] = {
 ....
      }
    }