← Back to team overview

launchpad-dev team mailing list archive

Re: zope class registry

 

Gary Poster wrote:
> On Dec 2, 2009, at 11:41 AM, Muharem Hrnjadovic wrote:
> 
>> Gary Poster wrote:
>>> On Dec 2, 2009, at 10:41 AM, Muharem Hrnjadovic wrote:
>>>
>>>> Quick question:
>>>>
>>>> do we use the zope class registry anywhere?
>>> I doubt it.
>>>
>>>> Is it safe to use within
>>>> Launchpad?
>>> I'd prefer to use utility registration if that can work with your use case.
>> Sorry for not being precise enough. In my particular case a number of
>> classes would implement the interface in question (IBuildFarmJob).
>>
>> I understood the utility registration mechanism requires that there is
>> exactly one class that implements a particular interface in which case I
>> could not use it for the interface/purpose at hand.
> 
> The class registry you showed had keys and values.
> 
> You can register different utilities for the same interface by
> providing a different name for each one (I think of this as a
> namespace).
Sorry for pestering you with daft questions but I have never dealt with
this before. How does one "register different utilities for the same
interface by providing a different name"?

> You can then get all of the utilities for that interface with
> getUtilitiesFor.  From docs:
> 
>>>> sorted(components.getUtilitiesFor(tests.I2))
> [(u'', U12(2)), (u'three', U12(3))]
> 
> In that example, ``components`` could be obtained as follows:
> 
> from zope.component import getSiteManager
> components = getSiteManager()
> 
> Is that sufficient?
This is *very* helpful. Thank you!

Best regards

-- 
Muharem Hrnjadovic <muharem@xxxxxxxxxx>
Public key id   : B2BBFCFC
Key fingerprint : A5A3 CC67 2B87 D641 103F  5602 219F 6B60 B2BB FCFC

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References