[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - metaConfigure.py:1.1.2.7
Jim Fulton
jim@zope.com
Tue, 4 Jun 2002 13:23:55 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv25226/lib/python/Zope/App/ComponentArchitecture
Modified Files:
Tag: Zope3InWonderland-branch
metaConfigure.py
Log Message:
Added factory attribute to utility and service directives so that you
can specify a factory rather than an instance. This makes class source
files a little cleaner because they don't need to create an instance.
This is only useful when the instance can be created by calling the
factory without arguments.
=== Zope3/lib/python/Zope/App/ComponentArchitecture/metaConfigure.py 1.1.2.6 => 1.1.2.7 ===
]
-def utility(_context, component, provides, permission=None):
+def utility(_context, provides, component=None, factory=None, permission=None):
provides = _context.resolve(provides)
- component = _context.resolve(component)
+
+ if factory:
+ if component:
+ raise TypeError("Can't specify factory and component.")
+
+ component = _context.resolve(factory)()
+ else:
+ component = _context.resolve(component)
if permission is not None:
if permission == 'Zope.Public':
permission = CheckerPublic
checker = InterfaceChecker(provides, permission)
+
component = Proxy(component, checker)
return [
@@ -241,8 +249,15 @@
service_manager.provideService(serviceType, component)
-def service(_context, serviceType, component, permission=None):
- component = _context.resolve(component)
+def service(_context, serviceType, component=None, permission=None, factory=None):
+ if factory:
+ if component:
+ raise TypeError("Can't specify factory and component.")
+
+ component = _context.resolve(factory)()
+ else:
+ component = _context.resolve(component)
+
return [
Action(
discriminator = ('service', serviceType),