The request is for anything you need. Some frameworks pass a request
and response to the view and have other global objects and things, but
Pyramid tends to use the request to put all that stuff in one place.
Even semi-exceptions like 'context' that can be received separately
are also in the request. So I would do likewise, starting with
database connections.
In one application I have SQLAlchemy sessions to three databases, the
underlying engines to them, a Redis connection pool, an ldap3 pool,
things from tweens, and maybe other things. I tried different
strategies like add_request_method, a request subclass, and
pyramid_services. I ended up using a request subclass just because it
was easier to manage all those things together rather than piecemeal,
If I had only one or two I'd use add_request_method. And I use reify
as much as feasable.
Global things used across all requests can go into 'registry' or
'registry.settings', or you can use pyramid_services or the registry
interface API. Things like engines and connection pools are global and
thread-save so you can use them directly, although I ultimately found
it more convenient to make reified request properties that shadow
them. SQLAlchemy sessions have to be created for each request, so I
use reified properties for those, getting the engine from the
registry.
The features example you cited has an object that knows about the
features. But aren't boolean features ultimiately controlled by
configuration settings to enable them? You may be able to just use the
settings, or define your own settings, and then you wouldn't have to
make custom request properties.
Mike Orr <
slugg...@gmail.com>