pythonzopezcmlzope.component

What is the difference between a Zope utility defined with a factory versus a component?


It's a little confusing that ZCML registrations for Zope utilities can accept a component or a factory.

<utility component=".some.Class" />

versus

<utility factory=".some.Factory" />

What is the difference?


Solution

  • A factory creates utilities, while a utility registered as a component is an instance. Hence, if you look up a utility registered as a component, you will get the same object back every time. But if it's registered as a factory, you'll get a new instance every time.