Edgewall Software

Changes between Version 10 and Version 11 of TracDev/ComponentArchitecture


Ignore:
Timestamp:
Jul 4, 2007, 10:19:26 PM (17 years ago)
Author:
Dave Abrahams <dave@…>
Comment:

Add recursion caveat and disclaimer about the sensibility of this particular case and change wiki formatting to use something simpler

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/ComponentArchitecture

    v10 v11  
    155155== How Trac Uses Components ==
    156156
    157 The typical use of components in Trac starts with a top-level “service provider” that we'll pick up and use directly. Take, for example, {{{trac.perm.PermissionSystem}}}:
     157The typical use of components in Trac starts with a top-level “service provider” that we'll pick up and use directly. Take, for example, `trac.perm.PermissionSystem`:
    158158{{{
    159159#!python
     
    164164  ''Note that `trac.env.Environment` inherits `trac.core.ComponentManager`, so you'll typically see components initialized with an environment.''
    165165
    166 These are the first few lines of {{{PermissionSystem}}} as of r5790 (or [browser:trunk/trac/perm.py:r5790#L230 in context]):
     166These are the first few lines of `PermissionSystem` as of r5790 (or [browser:trunk/trac/perm.py:r5790#L230 in context]):
    167167{{{
    168168#!python
     
    177177Note that this `Component`:
    178178 1. implements the `IPermissionRequestor` interface
    179  1. has an extension point for registering all the Components implementing {{{IPermissionRequestor}}} ([browser:trunk/trac/perm.py:r5790#L40 in context]):
     179 1. has an extension point for registering all the Components implementing `IPermissionRequestor` ([browser:trunk/trac/perm.py:r5790#L40 in context]):
    180180{{{
    181181#!python
     
    187187}}}
    188188
    189   ''Note that interface authors have not always been consistent about declaring the "{{{self}}}" parameter in signatures.''
    190 
    191 When we use {{{PermissionSystem}}}, the plugin system will have automatically gathered up all implementations of {{{IPermissionRequestor}}} and placed them in {{{PermissionSystem}}}'s list of {{{requestors}}}.
    192 In this specific case `PermissionSystem` will be part of that list as well, because it implements that interface as well. In no way a Component is bound to implement the interfaces it declares an extension point for, the two operations being entirely independent. But when that make sense, it's entirely possible to do so.
    193 
    194 Next in {{{PermissionSystem}}} there is a declaration of an {{{ExtensionOption}}} called {{{store}}}:
     189  ''Note that interface authors have not always been consistent about declaring the “`self`” parameter in signatures.''
     190
     191When we use `PermissionSystem`, the plugin system will have automatically gathered up all implementations of `IPermissionRequestor` and placed them in `PermissionSystem`'s list of `requestors`.
     192In this specific case `PermissionSystem` will be part of that list as well, because it implements the `IPermissionRequestor` interface. In no way a Component is bound to implement the interfaces it declares an extension point for, the two operations being entirely independent. But when that make sense, it's entirely possible to do so.
     193
     194  ''Note: it's certainly debatable whether it makes sense in this particular case—but if you '''do''' decide to do it, watch out for infinite recursion as `PermissionStore` does [browser:trunk/trac/perm.py:r5790#L380 here].
     195
     196Next in `PermissionSystem` there is a declaration of an `ExtensionOption` called `store`:
    195197{{{
    196198#!python
     
    201203
    202204}}}
    203 The above adds an option called {{{permission_store}}} to {{{trac.ini}}}, declares that the component named by the option implements {{{IPermissionStore}}}, and sets its default to {{{DefaultPermissionStore}}}.  See [browser:trunk/trac/config.py trac.config] for {{{ExtensionOption}}} and friends.  Methods of service providers such as {{{PermissionSystem}}} are commonly a thin forwarding layer over such an {{{ExtensionOption}}}.  For example:
     205The above adds an option called `permission_store` to `trac.ini`, declares that the component named by the option implements `IPermissionStore`, and sets its default to `DefaultPermissionStore`.  See [browser:trunk/trac/config.py trac.config] for `ExtensionOption` and friends.  Methods of service providers such as `PermissionSystem` are commonly a thin forwarding layer over such an `ExtensionOption`.  For example:
    204206{{{
    205207#!python
     
    211213        return self.store.get_all_permissions()
    212214}}}
    213 Thus, service providers are directly manipulated from Python, and are customized through the automatic aggregation of components implementing {{{ExtensionPoint}}}s and through configuration of {{{ExtensionOption}}}s by Trac administrators.
     215Thus, service providers are directly manipulated from Python, and are customized through the automatic aggregation of components implementing `ExtensionPoint`s and through configuration of `ExtensionOption`s by Trac administrators.
    214216
    215217----