Skip to content

Instantly share code, notes, and snippets.

@privateblue
Created December 20, 2013 02:29
Show Gist options
  • Save privateblue/8049627 to your computer and use it in GitHub Desktop.
Save privateblue/8049627 to your computer and use it in GitHub Desktop.
// kinja-service library
trait SsoServiceComponent extends ServiceComponent {
val ssoService: SsoService
class SsoService extends Service {
def authorByToken(token: String): Author = {
lookupAuthorInDatabase(token)
}
}
}
trait InvitesServiceComponent extends ServiceComponent {
self: SsoServiceComponent =>
val invitesService: InvitesService
class InvitesService extends Service {
def invite(token: String, invitee: Author): Unit = {
val inviter = ssoService.authorByToken(token)
saveInvitationToDatabase(inviter, invitee)
}
}
}
// kinja-core application
object ServiceContext extends SsoServiceComponent with InvitesServiceComponent {
val ssoService = new SsoService
val invitesService = new InvitesService
}
object InvitesController extends Controller {
// mapped to route /api/invite/$authorId
def invite(token: String, invitee: Author) = Action {
ServiceContext.invitesService.invite(token, invitee)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment