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

Chris McDonough chrism at plope.com
Mon Nov 23 22:24:00 EST 2009


We've been handling some constructive criticisms from repoze.bfg developers 
with respect to verbosity resulting from use of unnamed utility registrations 
in a component architecture registry.

These criticisms, and our ameliorations are detailed here:
 
<http://docs.repoze.org/bfg/1.1/designdefense.html#bfg-uses-the-zope-component-architecture-zca>

In repoze.bfg, we've actually decided to use a subclass of the component 
registry which also inherits from "dict".  This makes it possible to spell 
common unnamed "utility" registrations and lookups as:

utility = SomeUtilityImplementation()
registry['someutility'] = utility
someutility = registry['someutility']

Instead of the more familiar:

class ISomeUtility(Interface):
     pass

utility = SomeUtilityImplementation()
registry.registerUtility(utility, ISomeUtility)

Doing this was extremely simple.  Here's the "meat" of the subclass:

from zope.component.registry import Components

class Registry(Components, dict):
     pass

I think it would be reasonable to make this change in zope.component itself. 
Dissenters?

- C


More information about the Zope-Dev mailing list