Skip to content

Instantly share code, notes, and snippets.

@sullivan-
Created May 7, 2013 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sullivan-/5529886 to your computer and use it in GitHub Desktop.
Save sullivan-/5529886 to your computer and use it in GitHub Desktop.
package congeal.examples.flat
import congeal._
case class S(sName: String)
case class T(tName: String)
case class U(uName: String)
trait SRepository {
def getS(sName: String): Option[S] = Some(S(sName))
}
trait TRepository {
def getT(tName: String): Option[T] = Some(T(tName))
}
trait URepository {
def getU(uName: String): Option[U] = Some(U(uName))
}
trait SService extends hasDependency[SRepository] {
def getS(sName: String): Option[S] = sRepository.getS(sName)
}
trait TService extends hasDependency[TRepository] {
def getT(tName: String): Option[T] = tRepository.getT(tName)
}
trait UService extends hasDependency[URepository] {
def getU(uName: String): Option[U] = uRepository.getU(uName)
}
trait Root extends
hasPart[SRepository] with
hasPart[TRepository] with
hasPart[URepository] with
hasPart[SService] with
hasPart[TService] with
hasPart[UService]
abstract class Application extends componentApi[Root] {
println(sRepository.getS("testSName"))
println(sService.getS("testSName"))
println(tRepository.getT("testTName"))
println(tService.getT("testTName"))
println(uRepository.getU("testUName"))
println(uService.getU("testUName"))
}
/* outputs
Some(S(testSName))
Some(S(testSName))
Some(T(testTName))
Some(T(testTName))
Some(U(testUName))
Some(U(testUName))
*/
object ApplicationTest extends App {
new Application with componentImpl[Root]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment