Created
May 7, 2013 02:36
-
-
Save sullivan-/5529886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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