launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #01922
Re: zope class registry
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.
--
Francis J. Lacoste
francis.lacoste@xxxxxxxxxxxxx
Attachment:
signature.asc
Description: This is a digitally signed message part.
Follow ups
References