Last active
December 31, 2015 21:58
-
-
Save privateblue/8049957 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 | |
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 = { | |
val inviter = authorResolver(token) | |
saveInvitationToDatabase(inviter, invitee) | |
} | |
} | |
case class InviteMessage(token: String, invitee: Author) | |
// kinja-core application | |
object SsoService extends service.SsoService | |
object InvitesService extends service.InvitesService | |
import service.model.InviteMessage | |
class InvitesActor extends Actor { | |
def receive = { | |
case InviteMessage(token, invitee) => | |
val authorResolver = (tk: String) => SsoService.authorByToken(tk) | |
InvitesService.invite(token, invitee, authorResolver) | |
// these two lines above are equivalent to | |
// InvitesService.invite(token, invitee, SsoService.authorByToken _) | |
} | |
} | |
val invitesActor = akka.actor.ActorSystem("kinja-core").actorOf(Props(classOf[InvitesActor], "invites-actor")) | |
// kinja-mantle application | |
import service.model.InviteMessage | |
object InvitesApiClient { | |
def invite(token: String, invitee: Author): Unit = { | |
val invitesService = context.actorSelection("akka.tcp://kinja-core@localhost:2552/user/invites-actor") | |
invitesService ! InviteMessage(token, invitee) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment