Edgewall Software

Changes between Version 17 and Version 18 of TracDev/ComponentArchitecture


Ignore:
Timestamp:
Nov 21, 2010, 1:00:32 PM (13 years ago)
Author:
Sebastian Krysmanski <sebastian@…>
Comment:

Condesed the note about which components get into an extension point

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/ComponentArchitecture

    v17 v18  
    118118Here, the `TodoList` class declares an extension point called `observers` with the interface `ITodoObserver`. The interface defines the ''contract'' that extending components need to conform to.
    119119
    120 The `TodoList` component notifies the observers inside the `add()` method by iterating over `self.observers` and calling the `todo_added()` method for each. This works because the `observers` attribute is a [http://users.rcn.com/python/download/Descriptor.htm descriptor]: When it is accessed, it finds all registered components that declare to extend the extension point. For each of those components, it gets the instance from the component manager, potentially activating it if it is getting accessed for the first time.
    121 
    122 '''Note:''' Component classes are registered at module load time. A specific component is instantiated on first use, either when accessing an extension point for an interface implemented by that component, or when calling the component constructor as `ComponentName(self.compmgr)`. The former use requires the component to be enabled in the `[components]` section of [wiki:TracIni trac.ini], while in the latter use the component will be instantiated regardless. Note that in this last case, even though the component is instantiated, it's only made available through the extension points if it's enabled in `[components]`.
     120The `TodoList` component notifies the observers inside the `add()` method by iterating over `self.observers` and calling the `todo_added()` method for each. This works because the `observers` attribute is a [http://users.rcn.com/python/download/Descriptor.htm descriptor]: When it is accessed, it finds all ''enabled'' components that declare to extend the extension point. For each of those components, it gets the instance from the component manager, potentially activating it if it is getting accessed for the first time.
     121
     122''Note:'' Only component classes that are enabled (in the `[components]` section of [wiki:TracIni trac.ini]) will be available when iterating over an extension point (like in the code above). Thus it's ''not enough'' to only instantiate a component (e.g. by calling the component constructor as `ComponentName(self.compmgr)`) but one needs to enable it as well.
    123123
    124124== Plugging in to an extension point ==