私はScalaとPlay全体にかなり慣れていないので、これを解決する私の方法は正しいものではないかもしれません。私はScala2.9.1とplay-mini_2.9.1-2.0.1を使用しています。
私は通常ルートを含むApp.scalaを持っています。しかし、私の意図は、このファイルにすべての可能なルートを挿入するのではなく、エンティティごとに分割することです。私の場合:ユーザー、役割、プロセス。
これを達成するために、私はそのようなことを試みました:
//in App.scala
object App extends Application {
println("Checking Database")
...
println("Resume executions from database")
...
def route = Routes(Process.routes :: User.routes) // I know this is wrong but I think you get what I want to do...
}
//in Process.scala
object Process {
val routes = Routes(
{
case GET(Path("/process")) => Action{ request =>
// returns a list of processes
}
case GET(Path("/process")) & QueryString(qs) => Action{ request =>
val id = QueryString(qs,"id").getOrElse(0)
// return process by id
}
}
)
}
//in User.scala
object User {
val routes = Routes(
{
case GET(Path("/user")) => Action{ request =>
// returns a list of processes
}
case GET(Path("/user")) & QueryString(qs) => Action{ request =>
val id = QueryString(qs,"id").getOrElse(0)
// return process by id
}
}
)
}
これは最初のステップにすぎません。私の最終的な目標は、指定されたパッケージからすべてのオブジェクト(プロセス、ユーザーなど)を動的にロードすることです。これをどのように行うことができるかについてのアイデアはありますか?