Table of Contents

Class PluginStateService

Namespace
SharpConsoleUI.Core
Assembly
SharpConsoleUI.dll

Service that manages the plugin system state, including plugin loading, service registration, and factory management. This service follows the established manager pattern for state management.

public class PluginStateService : IDisposable
Inheritance
PluginStateService
Implements
Inherited Members

Constructors

PluginStateService(ConsoleWindowSystem, ILogService?, PluginConfiguration?)

Initializes a new instance of the PluginStateService class.

public PluginStateService(ConsoleWindowSystem windowSystem, ILogService? logService = null, PluginConfiguration? configuration = null)

Parameters

windowSystem ConsoleWindowSystem

The console window system instance.

logService ILogService

Optional log service for diagnostics.

configuration PluginConfiguration

Optional plugin configuration.

Properties

Configuration

Gets the plugin configuration.

public PluginConfiguration Configuration { get; }

Property Value

PluginConfiguration

CurrentState

Gets the current state of the plugin system.

public PluginState CurrentState { get; }

Property Value

PluginState

LoadedPlugins

Gets the list of loaded plugins.

public IReadOnlyList<IPlugin> LoadedPlugins { get; }

Property Value

IReadOnlyList<IPlugin>

RegisteredActionProviderNames

Gets the names of all registered action providers.

public IReadOnlyCollection<string> RegisteredActionProviderNames { get; }

Property Value

IReadOnlyCollection<string>

RegisteredControlNames

Gets the names of all registered plugin controls.

public IReadOnlyCollection<string> RegisteredControlNames { get; }

Property Value

IReadOnlyCollection<string>

RegisteredLegacyServiceTypes

Gets the types of all registered plugin services (legacy pattern).

[Obsolete("Legacy type-based services are deprecated. Use RegisteredServiceNames instead.")]
public IReadOnlyCollection<Type> RegisteredLegacyServiceTypes { get; }

Property Value

IReadOnlyCollection<Type>

RegisteredServiceNames

Gets the names of all registered service plugins.

public IReadOnlyCollection<string> RegisteredServiceNames { get; }

Property Value

IReadOnlyCollection<string>

RegisteredServices

Gets all registered service plugin instances.

public IReadOnlyCollection<IPluginService> RegisteredServices { get; }

Property Value

IReadOnlyCollection<IPluginService>

RegisteredWindowNames

Gets the names of all registered plugin windows.

public IReadOnlyCollection<string> RegisteredWindowNames { get; }

Property Value

IReadOnlyCollection<string>

Methods

CreateControl(string)

Creates a control instance from a plugin-registered factory.

public IWindowControl? CreateControl(string name)

Parameters

name string

The name of the control to create.

Returns

IWindowControl

The created control instance, or null if not found.

CreateWindow(string)

Creates a window instance from a plugin-registered factory.

public Window? CreateWindow(string name)

Parameters

name string

The name of the window to create.

Returns

Window

The created window instance, or null if not found.

Dispose()

Disposes the plugin state service and all loaded plugins.

public void Dispose()

ExecutePluginAction(string, string, Dictionary<string, object>?)

Executes a plugin action using the agnostic pattern.

public void ExecutePluginAction(string providerName, string actionName, Dictionary<string, object>? context = null)

Parameters

providerName string

The name of the action provider.

actionName string

The name of the action to execute.

context Dictionary<string, object>

Optional execution context (will include WindowSystem automatically).

GetActionProvider(string)

Gets an action provider by name.

public IPluginActionProvider? GetActionProvider(string providerName)

Parameters

providerName string

The unique name of the action provider.

Returns

IPluginActionProvider

The action provider instance, or null if not found.

GetPlugin(string)

Gets a plugin by name.

public IPlugin? GetPlugin(string name)

Parameters

name string

The plugin name to search for.

Returns

IPlugin

The plugin instance, or null if not found.

GetService(string)

Gets a service plugin by name using the reflection-free pattern.

public IPluginService? GetService(string serviceName)

Parameters

serviceName string

The unique name of the service to retrieve.

Returns

IPluginService

The service plugin instance, or null if not found.

GetService<T>()

Gets a service instance registered by a plugin (legacy type-based pattern). This method is obsolete. Use GetService(serviceName) instead.

[Obsolete("Use GetService(serviceName) instead. Type-based service lookup will be removed in a future version.")]
public T? GetService<T>() where T : class

Returns

T

The service instance, or null if not found.

Type Parameters

T

The service type to retrieve.

HasService(string)

Checks if a service plugin with the specified name is registered.

public bool HasService(string serviceName)

Parameters

serviceName string

The service name to check.

Returns

bool

True if the service is registered, false otherwise.

IsPluginLoaded(string)

Checks if a plugin with the specified name is loaded.

public bool IsPluginLoaded(string name)

Parameters

name string

The plugin name to check.

Returns

bool

True if the plugin is loaded, false otherwise.

LoadPlugin(IPlugin)

Loads a plugin instance and registers its contributions.

public void LoadPlugin(IPlugin plugin)

Parameters

plugin IPlugin

The plugin to load.

LoadPlugin(string)

Loads a plugin from a specific DLL file path (agnostic loading).

public void LoadPlugin(string dllPath)

Parameters

dllPath string

The path to the plugin DLL file.

Exceptions

ArgumentNullException

Thrown if dllPath is null or empty.

LoadPlugin<T>()

Loads a plugin of the specified type.

public void LoadPlugin<T>() where T : IPlugin, new()

Type Parameters

T

The plugin type to instantiate and load.

LoadPluginsFromDirectory(string?)

Loads plugins from the specified directory. If no path is specified, uses the "plugins" subdirectory of the application's base directory.

public void LoadPluginsFromDirectory(string? pluginsPath = null)

Parameters

pluginsPath string

Optional path to the plugins directory.

UnloadPlugin(IPlugin)

Unloads a plugin and removes its contributions. Note: This is a stub implementation. Full unloading support will be added in a future version.

[Obsolete("Plugin unloading is not fully implemented yet. This method disposes the plugin but does not remove its registered contributions.")]
public void UnloadPlugin(IPlugin plugin)

Parameters

plugin IPlugin

The plugin to unload.

UpdateConfiguration(PluginConfiguration)

Updates the plugin configuration.

public void UpdateConfiguration(PluginConfiguration configuration)

Parameters

configuration PluginConfiguration

The new configuration.

Events

PluginLoaded

Event raised when a plugin is loaded.

public event EventHandler<PluginEventArgs>? PluginLoaded

Event Type

EventHandler<PluginEventArgs>

PluginUnloaded

Event raised when a plugin is unloaded.

public event EventHandler<PluginEventArgs>? PluginUnloaded

Event Type

EventHandler<PluginEventArgs>

ServiceRegistered

Event raised when a service is registered.

public event EventHandler<ServiceRegisteredEventArgs>? ServiceRegistered

Event Type

EventHandler<ServiceRegisteredEventArgs>

ServiceUnregistered

Event raised when a service is unregistered.

public event EventHandler<ServiceUnregisteredEventArgs>? ServiceUnregistered

Event Type

EventHandler<ServiceUnregisteredEventArgs>

StateChanged

Event raised when the plugin state changes.

public event EventHandler<PluginStateChangedEventArgs>? StateChanged

Event Type

EventHandler<PluginStateChangedEventArgs>