Article Plugin Lifecycle

The plugin manager orchestrates plugin enablement and configuration. It's management lifecycle begins when the platform is first accessed/started and continues until the platform process is terminated.

Plugin Manager Lifecycle

When initialization or re-initialization is required, the plugin manager executes the following process:
  1. If changes were made to enabled plugins, any newly disabled installable plugins are uninstalled.
  2. The BeforeInitialization event is fired on PluginManager and all event handlers are unregistered.
  3. All plugins are unloaded (all Plugin Manager references to plugins are removed, allowing the old instances of plugins to be cleaned up by the garbage collector).
  4. All enabled plugins are instantiated one-by-one.  As they are instantiated, translatable plugins are given their translations and configurable plugins are given their configuration.
  5. Any IBeforeInitialization plugins execute.
  6. All platform and custom Apis are registered.
  7. All plugins' Initialize() methods are called.  This is an appropriate time for plugins to register event handlers and interact with other plugins.
  8. The AfterInitialization event is fired on PluginManager and all event handlers are unregistered.
  9. Any newly enabled or newly upgraded installable plugins are installed.

While plugins are being reloaded (the majority of the flowchart above), the platform utilizes a distributed lock, ensuring that only one instance of the platform (which exists on each web node and each job server node) performs a plugin reload at a time. This ensures that one time processes, for example, installation, only occur once per site instance and not once per platform instance.

Plugin Lifecycle

From the perspective of a single plugin, the lifecycle appears as

Where the plugin is

  1. Instantiated. A new instance of the plugin is created when the plugin manager initializes or re-initializes plugins.
  2. Translated. Translatable plugins are given their translations.
  3. Configured. Configurable plugins are given their configuration.
  4. Any IBeforeInitialization execute their BeforeInitialization(...) logic.
  5. All platform and custom Apis are registered.
  6. Initialized. All plugins are initialized. This is an appropriate time to register event handlers against the in-process API or reference other plugins via PluginManager.
  7. Installed. Installable plugins' Install() methods are called if the plugin was not previously installed or an earlier/later version was previously installed.
  8. Executed. All plugins are allowed to execute normally. At this time, the platform will interact with special-use plugins and plugins will be notified whenever their registered events fire.
  9. Destroyed. When the plugin manager re-initializes, it removes all references to existing plugins and allows the .net garbage collector to clean up unreferenced plugins. If the plugin is installable and was newly disabled, it's Uninstall() method will be called.