[Zope3-Users] Re: looking for something like getUtilitiesFor...

Philipp von Weitershausen philipp at weitershausen.de
Tue Sep 19 03:59:09 EDT 2006

Chris Withers wrote:
> Philipp von Weitershausen wrote:
>> Utilities are never created when they're looked up. They're created 
>> when registered. Singletons (instances) are registered with the 
>> utility registry, never factories.
> Ah, yes, of course, I think I'm looking for local utilities...

But even global utilities are *first* instantiated from their factory, 
then registered as singleton instances.

>>> and all I'm then doing with the list is generating a drop-down for 
>>> people to select from...
>> getUtilitiesFor is all we have. If you want that drop-down, consider 
>> using UtilityVocabulary from zope.app.component.vocabulary, e.g.:
>>  class FooUtilityNames(UtilityVocabulary):
>>      interface = IFoo
>>      nameOnly = True
>>      classProvides(IVocabularyFactory)
>> Register that as a utility:
>>   <utility component="...FooUtilityNames" name="Foo Utilities"/>
>> Then you can refer to it from a schema definition (Choice field).
> Hmm, okay, how have the UI's for the creation of local utilities been 
> built? (I'm thinking there must be some kind of drop-down somewhere with 
> an "Add list" as in Zope 2's ZMI, and that must include the available 
> types of local utility?)

Sure. Just use the standard "Add" menu in Zope 3. Some of the items 
there are potential local utilities, such as the Catalog, Cookie Client 
Id Manager, Error Logging Utiltiy, etc. You can add these objects 
anywhere, though it is recommended to do it within ++etc++site. The 
thing that makes them available as utilities is the registration. All 
objects have a "Registration" tab.

> Also, more theoretically, would you see indexes for a catalog as being 
> local utilities. If not, what would you see them as being?

The catalog is the local utility. It functions as a container for 
indices. The catalog employs object event subscribers that tell it when 
objects have changed. THe catalog dispatches this action to its 
contained indices. That's about all the catalog does in Zope 3. You'll 
have to do everything else :).


More information about the Zope3-users mailing list