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

Philipp von Weitershausen philipp at weitershausen.de
Mon Sep 18 18:50:54 EDT 2006


Chris Withers wrote:
> ...but which just gets the names of utilities available for a particular 
> interface.
> 
> The reason I ask is that getUtilitiesFor returns tuples of name and 
> utility. This seems wasteful, particular when the utilities need to be 
> created from factories,

Utilities are never created when they're looked up. They're created when 
registered. Singletons (instances) are registered with the utility 
registry, never factories.

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

Philipp



More information about the Zope3-users mailing list