[Zope3-Users] Utilities

Albertas Agejevas alga at pov.lt
Mon Jun 5 07:56:11 EDT 2006


On Mon, Jun 05, 2006 at 01:14:58AM -0500, David Johnson wrote:
> What is the best to find the nearest utility without using a name? 
> 
> zapi.getUtility() seems to require a name (though the documentation
> implies otherwise).

The default name is ''.  If you're asking for z.c.getUtility(ISomething),
you'll get that -- the nearest utility with a given interface and name
''.  These used to be called services three years ago.

> zapi.getAllRegisiteredUtilitiesFor() works but it
> seems to me if you have lots of utilities in other contexts, it would
> query those as well, and thereby be slow in a large application.
> 
> I come across this problem frequently and haven't figured out the best
> way to deal with it.

If you want to get all utilities with a given interface, use
z.c.getUtilitiesFor(ISomething).  You'll get the nearest utility with
each given name.

Albertas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20060605/86a95446/attachment.bin


More information about the Zope3-users mailing list