Hi,
the documentation is quite clear about the "Don't do that!!!" regarding usage of get_current_request(). But however I approach my problem, I end up with get_current_request being the best solution, so I thought I should ask for permission. ;-)
Here is my scenario:
I have some service object which is registered in my application registry and requested by my application code from there. The object is independent of Pyramid, can be used and tested in isolation, so everything's fine. Deep inside the service, I fire some events to allow logging of some debug information (generated http requests and so on). Now I would like to display this information in the debug toolbar, of course on a per request base. Obviously passing the request to my service object is not an option as it would break the decoupling. Passing some logging handler through the whole service API is not nice too. Actually that's what events are made for. So the event handler needs to know about the current request. Whatever solution I could think of, I would have to implement something like a thread local. And then I could also use the existing get_current_request.
Does anybody see a better solution?
cheers,
Achim