I am building a web service using Spray.io which sits on top of a core application built with Akka.
When I receive a request in, it gets processed by a spray route which in turn will send (using tell) the request on to an actor which processes the request and returns the response using the request context.
I authenticate & authorise the user within the initial route and this authentication/authorisation returns a user object containing data on the user.
I need to be able to access this user object within the core Akka application at various points. I don't want to have to pass it around as a parameter on every message (case class) sent to an actor as this just seems messy as at times I would be passing it to an actor just so it can be passed on to another. Is there a better/recommended way of making this object available to other actors in the system? Can it be attached to the request context itself or is that bad practice?
Thanks
If what you're trying to do is avoid the boilerplate of having to pass the authentication info when you create your case class instances, you could add an implicit argument list to them:
scala> implicit val i = 1
i: Int = 1
scala> case class X(s: String)(implicit val y: Int)
defined class X
scala> val x = X("foo")
x: X = X(foo)
scala> x.y
res4: Int = 1
you're still passing the authentication info with every message and you can't use pattern matching on the second argument list, but depending on what you are trying to accomplish it might work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With