Skip to content

Instantly share code, notes, and snippets.

// kinja-service library
class SsoService extends ApiService {
def authorByToken(token: String): Author = {
lookupAuthorInDatabase(token)
}
}
trait SsoServiceContract {
// kinja-service library
class SsoService extends ApiService {
def authorByToken(token: String): Author = {
lookupAuthorInDatabase(token)
}
}
case class AuthorByToken(token: String)
// kinja-service library
class SsoService extends ApiService {
def authorByToken(token: String): Author = {
lookupAuthorInDatabase(token)
}
}
class InvitesService extends Service {
def invite(token: String, invitee: Author, authorResolver: String => Author): Unit = {
// kinja-service library
trait SsoServiceComponent extends ServiceComponent {
val ssoService: SsoService
class SsoService extends Service {
def authorByToken(token: String): Author = {
lookupAuthorInDatabase(token)
}
akka {
worker-dispatcher {
type = BalancingDispatcher
}
actor.deployment {
"/my-read-pool/*" {
dispatcher = akka.worker-dispatcher
}
}
asyncpools {
my-read-pool {
size = 5
defaultTimeout = "2 seconds"
url = "jdbc:h2:mem:testDB;DATABASE_TO_UPPER=false"
user = ""
password = ""
driver = "org.h2.Driver"
}
import play.api.mvc._
import play.api.libs.json.Json
import play.api.libs.concurrent.Execution.Implicits.defaultContext
object MyController extends Controller {
def getName(id: Int) = Action.async {
MyRepository.getName(id)
.map { name: String =>
Ok(Json.obj("name" -> name))
import scala.slick.driver.H2Driver.simple._
object MyRepository {
val table = new Table[(Int, String)]("my_table") {
def id = column[Int]("id", O.PrimaryKey)
def name = column[String]("name")
def * = id ~ name
}
import org.pblue.asyncpools.slick.SlickPoolFactory
object MySlickPools extends SlickPoolFactory {
val myReadPool = newConfiguredSlickPool("my-read-pool")
val myWritePool = newConfiguredSlickPool("my-write-pool")
}
@privateblue
privateblue / kinja-core-di-3.scala
Last active December 28, 2015 18:39
mixed style dependency injection pattern for repositories and services
// COMMON-BASE LIBRARY
// dependencies
trait ConnectionPoolProvider {
protected val connectionPool: ConnectionPool
}
trait ExternalStuff {
protected val stuff = "stuff"