Using the Spark web framework - I'd like to avoid passing all parameters into every method signature (request user, etc). Is it suitable to use a context with static ThreadLocal properties?
I guess we don't have full control which thread services a request but guess Initializing with each call on the Spark API/boundary should be fine.
I fiddled around a bit and I think I found a good solution for this problem. According to the documentation:
/**
* Sets an attribute on the request
* (can be fetched in filters/routes later in the chain)
*
* @param attribute The attribute
* @param value The attribute value
*/
public void attribute(String attribute, Object value) {
/* ... */
}
So you can use set an attribute in the request itself and later fetch it. Pretty neat.
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