[Zope3-Users] Re: Creating utilities overhead
Philipp von Weitershausen
philipp at weitershausen.de
Tue May 3 15:16:14 EDT 2005
Andreas Jung wrote:
> I have an utility registered as
>
> <utility
> provides="textindexng.interfaces.ILexicon"
> factory="textindexng.lexicon.LexiconFactory"
> name="txng.lexicons.default"
>
> />
>
> trying to create a new Lexicon instance through
>
> lexicon zapi.createObject(None, 'txng.lexicons.default')
>
> does not work (Zope 2.8, Five) because the factory does not seem
> to be registered for IFactory.
>
> Adding
>
> <utility
> provides="zope.component.interfaces.IFactory"
> component="textindexng.lexicon.LexionFactory"
> name="txng.lexicons.default"
> />
>
> resolves the issue. But why is the explicit declaration of the factory
> necessary? IMO the first declaration implies the second one. So this
> looks like configuration overhead to me...thoughts?
This is actually a mixup of the term 'factory'. The 'factory' parameter
of the <utility /> directive might suggest that an IFactory is
registered, but as you found out, it isn't meant that way. With the
<utility /> directive, the parameter 'factory' means a globally
accessible callable (class constructor, function, etc.) that creates an
instance of the utility. Think of it as a "class factory", not a
"factory component" in the Zope 3 sense.
If you want an IFactory utility to be registered (so you can call
createObject, for example), you need to do this explicitly. Either with
a separate <utility /> directive like you quoted above, or (if you want
to save a line) with the <factory /> directive.
Philipp
More information about the Zope3-users
mailing list