Hi,

If I have a utility component whose initializaiton depends on the
availability of another utility, the initialization fails with a
Component Lookup Error. It seems that in the ZCML file, the utility
components are first created, and then at the end of the whole
configuration, they are registered. So if in the initilization code of
utility B I need to look up a utility A, the ZCML configuration will
fail.

As an example, I have a utility that reference a z3c.zalchemy engine.

class MyUtility(object):
    implements(IMyUtility)

    def __init__(self):
        engine = getUtility(z3c.zalchemy.interfaces.IAlchemyEngineUtility,
                            name=u'TheEngine').getEngine()

And the configuration goes like this:

<configure
    xmlns:alchemy="http://namespaces.zalchemy.org/alchemy";

    <alchemy:engine
        name="TheEngine"
        url="some db url" />

    <utility
        factory=".utility.MyUtility"
        permission="zope.Public"
        provides=".interfaces.IMyUtility" />

</configure>

The problem is that although the z3c eninge object is created before
the 'utility' directive is executed, it is not registered and
therefore can not be looked up when the 'utility' directive tries to
create the MyUtility object.

How does one usually solve such interdependencies?

-- 
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to