Skip to content

Latest commit

 

History

History
142 lines (107 loc) · 3.35 KB

File metadata and controls

142 lines (107 loc) · 3.35 KB

Trinity

Build Status

Trinity is a lightweight MVC framework based on Finagle, which can be described in Scala.

Concepts

  • We provide functions about MVC which does not support Finagle.
  • We support Domain Driven-Design by non CoC(Convention over Configuration).

Features

  • You can describe Actions over a Controller as a Finagle Service.
    • Routing information can described to action methods, like Scalatra.
    • Or, The Routing information can be aggregated on the outside of Controller, like Play2.
  • You can use Template Engine (such as Scalatra) with Trinity.

Functions

Supported Functions

  • Routing request to action
    • A action can be described as asynchronous process by using com.twitter.util.Future.
    • Or, You can also select action as synchronous process by using com.twitter.util.FuturePool.
    • We support an action adaptor for a process which returns scala.concurrent.Future.
  • Finagle's Request/Response Enhance
    • multi-part file upload
    • json format reponse
    • file resouce support
  • Binding to Template Engine
  • Testing
    • Unit testing
    • Integration testing
  • JRebel support

Unsupported Functions

  • Functions for Form, Validation
  • Functions for Persistence(sush as RDBMS/NoSQL)

License

Apache License, Version 2.0

Setup

Build Configuration

Please add configuration in following to Build.scala.

object AppBuild extends Build {
  val root = Project(
    id = "app",
    base = file("."),
    settings = Project.defaultSettings ++ Seq(
      resolvers ++= Seq(
        // ...
        "Sisioh Trinity Release Repository" at "http://sisioh.github.io/trinity/repos/release/",
       // ...
      ),
      libraryDependencies ++= Seq(
        // ...
        "org.sisioh" %% "trinity" % "0.0.7",
        // ...
      )
    )
  )
}

Bootstrap code

val config = Config.fromFile()
implicit val application = TrinityApplication(config)

application.registerController(new GreetingController)
application.start()   

Controller code

Scalatra like controller

class GreetingController(implicit application: TrinityApplication) extends SimpleController {

    get("/hello") {
      request =>
        responseBuilder.withPlain("Hello!").toFinagleResponseFuture
    }
    
}

Play2 like controller

class GreetingController(implicit application: TrinityApplication) extends AbstractController {

    def hello = FutureAction {
      request =>
        responseBuilder.withPlain("Hello!").toFinagleResponseFuture
    }

}

Please modify bootstrap for routing to Play2 like controler.

// ...
implicit val application = TrinityApplication(config)

val greetingController = new GreetingController
application.addRoute(Method.Get, "/hello", greetingController, greetingController.hello)

application.registerController(greetingController)
// ...

Build

$ sbt clean compile

Run

$ sbt run

Test

$ curl -X GET http://localhost:7070/hello
Hello!