For singletons I am using utilities and for "factories" adapters, multi
adapters, e.g.:
from zope.interface import Interface, implements
from zope.component import adapts
from pyramid.interfaces import IRequest
class IMyContext(Interface):
pass
class IMyService(Interface):
pass
class MyContext(object):
implements(IMyContext)
class MyService(object):
implements(IMyService)
adapts(IRequest, IMyContext)
def __init__(self, request, context):
pass
class OtherService(object):
implements(IMyService)
def includeme(config):
other_service = OtherService()
config.registry.registerUtility(other_service)
config.registry.registerAdapter(MyService)
def test():
from pyramid.testing import testConfig, DummyRequest
with testConfig() as config:
includeme(config)
other_service = config.registry.getUtility(IMyService)
assert IMyService.providedBy(other_service)
my_service = config.registry.getMultiAdapter((DummyRequest(),
MyContext()), IMyService)
assert IMyService.providedBy(my_service)
What would be the difference except a more or less unified API to retrieve
the services?
May be I am missing the point....
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.