[Zope3-dev] Context and Component Lookup

Jim Fulton jim@zope.com
Wed, 06 Aug 2003 10:19:12 -0400


Phillip J. Eby wrote:
> At 06:57 AM 8/6/03 -0400, Jim Fulton wrote:
> 
>> To implement this simpler component lookup strategy will require
>> resorting to a thread-global variable. This thread global variable
>> will be set during URL traversal and (probably) cleared when a request
>> is closed.
> 
> 
> You might be able to do that a lot more simply, if you just use an 
> explicit context object, and the context object has methods to look up 
> views, etc.  In peak.web, I use a TraversalContext class, mainly to be 
> able to compute relative and absolute URLs of resources, but you could 
> use a similar approach for this.
> 
> Basically, a TraversalContext holds a reference to the interaction (a 
> per-request IPublication, but for zope.app you could just hold the 
> request instead), a traversable (the content object adapted to a 
> traversing protocol) and a subject (the original content object).  A 
> traversal context also knows its parent context.
> 
> By calling a method on a traversal context, passing in a name, you can 
> get a new traversal context that's a child of the previous context, and 
> has traversed to the appropriate content object.  So, in peak.web, the 
> main thing that gets passed around are these context objects, because 
> they give access to everything: the request, traversal adapters, and 
> content objects.  They can safely cache a variety of things, they can 
> delegate aspects of their behavior to the traversal or content objects, 
> and so on.  And, in peak.web they have the equivalent responsibility of 
> adapting content objects to viewable entities.  See ITraversalContext:

The existing context objects have a similar role in Zope 3 today.
They are very explicit, but, they are *too* explicit.  Way too much
code has to be aware of them.  It doesn't get too bad until the *content*
needs to get to them. Having a wrapper around doesn't help unless the content's
methods are either bound to the context or passed the context. Both have been
found to be a huge burden.  This burden is tha main motivation for the
current "container geddon". in which I'm looking at using explicit container
references for context-aware content.

Jim


-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (703) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org