Vixen
02b45cc4
csharp
public sealed class PluginHost

Loads plugins, activates them in order, and takes them back out again.

Read the guide page for this →

Remarks

Nothing here throws for a plugin's mistake. A manifest that does not parse, an assembly that is not there, an entry type that cannot be found, a constructor that throws, an Activate that throws, a command id somebody already owns — all six are a PluginDiagnostic and a Failed, and the editor carries on opening. An editor that will not start because of a third-party plugin is an editor whose users learn to distrust plugins.

⚠ A failed activation is rolled back completely. A plugin that registered two commands and then threw would otherwise leave both of them behind, pointing into an assembly nothing else refers to — half a plugin, permanently, and a context that can never be collected. The registration scope is disposed on the way out of the failure, which is the same code the unload path runs.

⚠ Not thread-safe, on purpose. The shell's registries are not, the docking host is not, and a loader that took a lock would be advertising a guarantee the things it writes to do not make. Load, unload and reload from the frame thread.

Fields and properties (5)

  • public PluginServices Services

    What plugins can ask the host for.

  • public IList<IContributionScanner> Scanners

    What reads a loaded assembly's declarations. Added by the host at start-up.

  • public IReadOnlyList<LoadedPlugin> Plugins

    Every plugin the host has been asked to load, whatever became of it.

  • public IReadOnlyList<PluginDiagnostic> Diagnostics

    Everything the host has had to say, across every pass.

  • public IReadOnlyCollection<string> Suppressed

    The plugins the user has switched off, whatever their manifests say.

Events (1)

  • public Action<LoadedPlugin>? Changed

    Raised after a plugin activates or is unloaded.

Methods (15)

  • public PluginHost(EditorShell shell, PluginServices? services = null)

    Creates a host over a shell.

  • public void Suppress(IEnumerable<string> ids)

    Declares which plugins the user has switched off, before anything is loaded.

  • public bool Disable(string id)

    Switches a plugin off, now and for the next session.

  • public PluginReport Enable(string id)

    Switches one back on and starts it.

  • public bool IsSuppressed(string id)

    Whether a plugin is switched off, by its author or by the user.

  • public LoadedPlugin? Find(string id)

    The plugin with an id, or null.

  • public PluginReport Load(PluginCatalog catalog)

    Loads and activates everything a scan found.

  • public PluginReport Load(IReadOnlyList<PluginDescriptor> descriptors)

    Loads and activates a set of plugins.

  • public bool Unload(string id)

    Takes a plugin back out.

  • public void UnloadAll()

    Takes every active plugin back out, in reverse activation order.

  • public PluginReport Reload(string id)

    Unloads a plugin, re-reads its manifest, and activates it again.

  • public bool WaitForCollection(string id, TimeSpan timeout)

    Waits for an unloaded plugin's assemblies to actually leave memory.

  • public void Update(TimeSpan delta)

    Runs every active plugin's per-frame work, once.

  • public LoadedPlugin Activate(string id, string name, IEditorPlugin module, PluginLoadContext? context = null)

    Activates a module that is compiled in, through the door a third party comes through.

  • public void Declared(PluginContext context, Assembly assembly)

    Runs every registered scanner over one loaded assembly.

Used by (11)

  • EditorApplicationVixen.Editor.App
  • EditorScriptTestsVixen.Editor.Scripts.Tests
  • EditorScriptsVixen.Editor.Scripts
  • EditorSessionVixen.Editor.Testing
  • LoadingTestsVixen.Editor.Plugin.Tests
  • ModuleTestsVixen.Editor.Plugin.Tests
  • OutOfTreePluginTestsVixen.Editor.App.Tests
  • PluginManagerViewVixen.Editor.App
  • ScriptModuleVixen.Editor.Scripts
  • ScriptsModuleVixen.Editor.Scripts
  • SwitchingTestsVixen.Editor.Plugin.Tests