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.
[toc]
Plugin Manager Lifecycle
- If changes were made to enabled plugins, any newly disabled installable plugins are uninstalled.
- The BeforeInitialization event is fired on PluginManager and all event handlers are unregistered.
- 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).
- 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.
- Any IBeforeInitialization plugins execute.
- All platform and custom Apis are registered.
- All plugins' Initialize() methods are called. This is an appropriate time for plugins to register event handlers and interact with other plugins.
- The AfterInitialization event is fired on PluginManager and all event handlers are unregistered.
- 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
- Instantiated. A new instance of the plugin is created when the plugin manager initializes or re-initializes plugins.
- Translated. Translatable plugins are given their translations.
- Configured. Configurable plugins are given their configuration.
- Any IBeforeInitialization execute their BeforeInitialization(...) logic.
- All platform and custom Apis are registered.
- 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.
- Installed. Installable plugins'
Install()
methods are called if the plugin was not previously installed or an earlier/later version was previously installed. - 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.
- 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.