[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:

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):

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):

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

- C

More information about the Zope-Dev mailing list