[Grok-dev] registering a factory as a (global) utility

Martijn Faassen faassen at startifact.com
Wed Apr 25 16:03:17 EDT 2007


Hi there,

A fairly common pattern is the need to register a factory as a utility. 
I thought that'd be just:

class Item:
     pass

grok.global_utility(Item, provides=IMyFactory)

Unfortunately that's not the case. This registers an *instance* of Item, 
as global utilities actually instantiate Item.

Now we could simply say that's wrong, and people should instantiate 
these themselves.

That would work, and that's fine when considered in isolation, but 
unfortunately that is assymetrical with local utility registration, 
where we can't require this. Local utilities should only instantiate 
from their factories when the object that has these utilities associated 
is actually installed.

It's still useful to have this for global utilities, though. I propose 
the following alternate directive to do this:

grok.global_utility_object(Item, provides=IMyFactory)

I chose a separate directive because making global_utility take either a 
factory or an instance requires all kinds of extra checks and is not as 
readable as having a separate directive. I'm not sure I'm happy about 
the name though.

Comments?

Regards,

Martijn



More information about the Grok-dev mailing list