[Zope3-Users] Utilities

Florian Lindner mailinglists at xgm.de
Mon Jun 5 05:12:54 EDT 2006


Am Montag, 5. Juni 2006 08:14 schrieb David Johnson:
> 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). 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.

getUtility does not require a name.

Example:

        from zope.app.zapi import getUtility
        from zope.app.homefolder.interfaces import IHomeFolderManager
        hfm = getUtility(IHomeFolderManager)

Regards,

Florian


>
> I come across this problem frequently and haven't figured out the best
> way to deal with it.


More information about the Zope3-users mailing list