Created
May 6, 2016 05:39
-
-
Save binshuohu/c331673845ebf7cec7a3b28bee900271 to your computer and use it in GitHub Desktop.
how to modularize scala code properly?
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
trait FooComponent { | |
def fooService: FooService | |
trait FooService { | |
def query: String | |
} | |
} | |
trait ConcreteFooComponent extends FooComponent { | |
val fooService = ??? | |
} | |
trait QueryRoutes { | |
this: FooComponent => | |
val queryRoute = get { | |
complete(fooService.query) | |
} | |
} | |
trait OtherRoutes { | |
val otherRoute = ??? | |
} | |
trait HttpService extends QueryRoutes with OtherRouters { // 编译不过,因为QueryRoutes声明了self type annotation | |
val route = queryRoute ~ otherRoute | |
} | |
object Main extends HttpService with ConcreteFooComponent with App { | |
} |
trait HttpService extends QueryRoutes with OtherRouters {
//加上
this: FooComponent =>
val route = queryRoute ~ otherRoute
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
trait HttpService extends QueryRoutes with OtherRouters {
this: FooComponent =>
val route = queryRoute ~ otherRoute
}