Changes between Version 10 and Version 11 of TracDev/ComponentArchitecture
- Timestamp:
- Jul 4, 2007, 10:19:26 PM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/ComponentArchitecture
v10 v11 155 155 == How Trac Uses Components == 156 156 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}}}: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`: 158 158 {{{ 159 159 #!python … … 164 164 ''Note that `trac.env.Environment` inherits `trac.core.ComponentManager`, so you'll typically see components initialized with an environment.'' 165 165 166 These are the first few lines of {{{PermissionSystem}}}as of r5790 (or [browser:trunk/trac/perm.py:r5790#L230 in context]):166 These are the first few lines of `PermissionSystem` as of r5790 (or [browser:trunk/trac/perm.py:r5790#L230 in context]): 167 167 {{{ 168 168 #!python … … 177 177 Note that this `Component`: 178 178 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]): 180 180 {{{ 181 181 #!python … … 187 187 }}} 188 188 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 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 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 196 Next in `PermissionSystem` there is a declaration of an `ExtensionOption` called `store`: 195 197 {{{ 196 198 #!python … … 201 203 202 204 }}} 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:205 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: 204 206 {{{ 205 207 #!python … … 211 213 return self.store.get_all_permissions() 212 214 }}} 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.215 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. 214 216 215 217 ----