Is scala's cake pattern possible with parametrized components?

Posted by Nicolas on Stack Overflow See other posts from Stack Overflow or by Nicolas
Published on 2012-11-20T16:13:25Z Indexed on 2012/11/20 17:00 UTC
Read the original article Hit count: 207

Parametrized components work well with the cake pattern as long as you are only interested in a unique component for each typed component's, example:

trait AComponent[T] {
  val a:A[T]

  class A[T](implicit mf:Manifest[T]) {
    println(mf)
  }
}

class App extends AComponent[Int] {
  val a = new A[Int]()
}

new App

Now my application requires me to inject an A[Int] and an A[String], obviously scala's type system doesn't allow me to extends AComponent twice. What is the common practice in this situation ?

© Stack Overflow or respective owner

Related posts about scala

Related posts about dependency-injection