[Zope-dev] make zope.component.registry.Components inherit from dict?

Hanno Schlichting hanno at hannosch.eu
Tue Nov 24 03:25:02 EST 2009


On Tue, Nov 24, 2009 at 5:53 AM, Matthew Wilkes
<matthew at matthewwilkes.co.uk> wrote:
> But, here is where the ZCA eyes come back into play, I wouldn't add
> this to the ZCA itself.  One reason being that Hanno's been working on
> a more useful persistent component root for Zope that brings in bits
> of OFS, hooking a dict in there would just be confusing.

Just to be clear here. The "five.localsitemanager" package
representing the canonical implementation of a persistent local
component registry in all Zope2 based projects does this since it's
beginning. When using the registry on your own, you are free to ignore
it's container API, but when using GenericSetup to populate such a
component registry, this is what essentially happens (leaving out the
GS parsing methods and helpers):

from zope.component import getSiteManager
from zope.ramcache.interfaces.ram import IRAMCache
from zope.ramcache.ram import RAMCache

sm = getSiteManager()
name = 'zope.ramcache.interfaces.ram.IRAMCache'
sm[name] = RAMCache()
ram = sm[name]
ram.__name__ = name
ram.__parent__ = sm
sm.registerUtility(ram, IRAMCache, name)

One explicit goal of this approach is to keep the data object and it's
registration as an utility separate, so you can unregister a
persistent utility without implicitly removing the only persistent
reference that exists to it. In this view you have a data object that
is persisted itself and you can give it a function by registering it
as a utility.

I'm not sure how this affects Chris proposal. But we already have a
commonly used subclass of the component registry that uses the dict
API in a somewhat different way here.

Hanno


More information about the Zope-Dev mailing list