Created
December 20, 2013 02:29
-
-
Save privateblue/8049627 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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