[Zope3-dev] Re: a new zcml directive?

Jean-Marc Orliaguet jmo at ita.chalmers.se
Thu Mar 16 10:47:27 EST 2006


Martijn Faassen wrote:

> Jean-Marc Orliaguet wrote:
> [snip]
>
>> OK, basically you mean that the 'annotations' given in your original 
>> post should implement a 'setdefault' method?
>
>
> I don't see how that would help - you'd still end up writing a factory 
> that uses the setdefault, right?
>
> I don't want to keep repeating factory code each time I want to do 
> this, including factory code that calls IAnnotations(), uses 
> setdefault() or anything else. I just want to say, I want to make an 
> adapter that uses this standardized factory code. How the factory code 
> does this is not very interesting, it's just that I don't want to keep 
> writing it over and over.
>
> Regards,
>
> Martijn


OK, you could pass the interface of the factory to the getter method and 
let it create the object based on this information. That wouldn't be 
exactly like setdefault(), but at least the factory code would be in the 
called method, not in the caller.

If I remember correctly the pattern I'm using (which I still think is 
OK) is to register a factory as a global utility and look up the factory 
by its interface.

so for instance to create a style or type "IStyle", I register:

  <cpsskins:setting
      name="style"
      schema=".style.IStyle"
      factory=".style.StyleFactory"
  />

with:

def setting(_context, name=u'', schema=None, factory=None):
...
    provideUtility(factory, IFactory, name)

then the annotation getter can contain a 'factory = getUtility(IFactory, 
name)'

regards
/JM



More information about the Zope3-dev mailing list