[Grok-dev] Re: Global utilities registered too early?
janwijbrand at gmail.com
Tue Jun 19 08:33:26 EDT 2007
On 6/19/07, Jan-Wijbrand Kolman <janwijbrand at gmail.com> wrote:
> > I'm trying to create/register a global utility by subclassing
> > grok.GlobalUtility. If I understand correctly, exactly one instance of
> > this utility class is created at registration time, right? It is this
> > instance that is returned when calling getUtility, right?
> > Now, in my case the __init__ of my utility class makes use of other
> > global utilities that are registered by a "third party" package
> > (called userschema). However, when creating the instance for my
> > utility class, the "third party" utilities are not registered (yet)
> > and thus cannot be found.
> > I'm not sure I fully understand why this is the case (and thus I do
> > not see a way around it yet). I also tried to <include
> > package="userschema" ?> just before the <grok:grok package="."/>
> > directive in my package's configure.zcml, but to no avail; My global
> > utility seems always to be registered before the utilities from
> > userschema are registered.
> > Maybe somebody can nudge me in the right direction with this?
> FYI: I put a print statement in registerUtility() in z.c.registry and
> indeed it seems utilities that are registered thru grok are registered
> *before any other* utility that gets registered in core zope packages
> and "third party non-grok" pacakges. HTH.
After more digging I think to understand it all a bit better:
registering a utility thru zcml is a two-stage rocket: first an
registration action is constructed (from the information provided in
the zcml directive) and then at some point later on in the
configuration process, these actions are actually executed (and thus
the actual utility registrations are made).
Creating the action objects is done before my grok.GlobalUtility is
registered, in the expected order, but the *execution* of these
actions is done thereafter. And thus the grok utitlities are
effectively created and registered before any other utility in the
I have no idea how to resolve this issue and it actually presents me
with a quite a nasty situation... I hope someone has an idea how to
overcome this problem: I'd be happy to help I just do not have a clear
idea where to start...
More information about the Grok-dev