launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #01926
Re: zope class registry
Francis J. Lacoste wrote:
> On December 2, 2009, Gary Poster wrote:
>> On Dec 2, 2009, at 12:47 PM, Francis J. Lacoste wrote:
>>> On December 2, 2009, 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).
>>>>
>>>> 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()
>>> Another possibility is to use subscriptions. You can register components
>>> for the IBuildFarmJob interface and get all the registered subscribers.
>> Absolutely.
>>
>> FWIW, I don't like subscription adapters because their functionality can be
>> essentially duplicated in the way I described, with named utilities. I'm
>> trying to reduce the number of things to learn about in Zope's Component
>> Architecture in zope-dev. So I don't recommend them...but that's just me.
>> :-)
>
> Then what Gary says :-)
Thanking you both for the great advice :)
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
References