Okay, that answers another question I had, but I'm still not clear on how to get at that service object from a couple of places. For example, here's my Realm implementation: class InnerSpaceRealm: __implements__ = portal.IRealm def requestAvatar(self, avatarId, mind, *interfaces): if pb.IPerspective in interfaces: registry = ### how do i get this? avatar = UserPerspective(mind, registry.get(avatarId)) return pb.IPerspective, avatar, avatar.logout else: raise NotImplementedError("no interface") what's the right way to get that service object? this issue comes up again in my UserPerspective class, where i need to access that registry object during perspective_xxx methods... there is a part of me that just wants to use registry as a one-off class with a class variable that returns the current instance, but i don't like that part ;-)..... thanks again, -phil
Newly written programs should implement makeService() instead of updateApplication(). As a bonus, purely service-based programs can easily and cleanly do things like the above:
from twisted.application import service
class RegistryService(service.Service): def __init__(self): self.registry = registry.Registry()
def makeService(config): s = RegistryService() ... anotherS = SomeotherService() anotherS.setServiceParent(s) # Or s.setServiceParent(anotherS) ... return s # or return anotherS
`s' can be the parent service of other services, in which case it can be accessed simply by looking up the parent service, or it could be a child service of something else, in which case it would be accessed via a call to getServiceNamed() on the appropriate parent.
This avoids the need for globals and lets services/applications be more readily configurable alongside other services/applications (since neither will have global state that might interfer with the other).
Jp