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
windowSystemConsoleWindowSystemThe console window system instance.
logServiceILogServiceOptional log service for diagnostics.
configurationPluginConfigurationOptional plugin configuration.
Properties
Configuration
Gets the plugin configuration.
public PluginConfiguration Configuration { get; }
Property Value
CurrentState
Gets the current state of the plugin system.
public PluginState CurrentState { get; }
Property Value
LoadedPlugins
Gets the list of loaded plugins.
public IReadOnlyList<IPlugin> LoadedPlugins { get; }
Property Value
RegisteredActionProviderNames
Gets the names of all registered action providers.
public IReadOnlyCollection<string> RegisteredActionProviderNames { get; }
Property Value
RegisteredControlNames
Gets the names of all registered plugin controls.
public IReadOnlyCollection<string> RegisteredControlNames { get; }
Property Value
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
RegisteredServiceNames
Gets the names of all registered service plugins.
public IReadOnlyCollection<string> RegisteredServiceNames { get; }
Property Value
RegisteredServices
Gets all registered service plugin instances.
public IReadOnlyCollection<IPluginService> RegisteredServices { get; }
Property Value
RegisteredWindowNames
Gets the names of all registered plugin windows.
public IReadOnlyCollection<string> RegisteredWindowNames { get; }
Property Value
Methods
CreateControl(string)
Creates a control instance from a plugin-registered factory.
public IWindowControl? CreateControl(string name)
Parameters
namestringThe 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
namestringThe 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
providerNamestringThe name of the action provider.
actionNamestringThe name of the action to execute.
contextDictionary<string, object>Optional execution context (will include WindowSystem automatically).
GetActionProvider(string)
Gets an action provider by name.
public IPluginActionProvider? GetActionProvider(string providerName)
Parameters
providerNamestringThe 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
namestringThe 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
serviceNamestringThe 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
TThe service type to retrieve.
HasService(string)
Checks if a service plugin with the specified name is registered.
public bool HasService(string serviceName)
Parameters
serviceNamestringThe 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
namestringThe 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
pluginIPluginThe plugin to load.
LoadPlugin(string)
Loads a plugin from a specific DLL file path (agnostic loading).
public void LoadPlugin(string dllPath)
Parameters
dllPathstringThe 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
TThe 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
pluginsPathstringOptional 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
pluginIPluginThe plugin to unload.
UpdateConfiguration(PluginConfiguration)
Updates the plugin configuration.
public void UpdateConfiguration(PluginConfiguration configuration)
Parameters
configurationPluginConfigurationThe new configuration.
Events
PluginLoaded
Event raised when a plugin is loaded.
public event EventHandler<PluginEventArgs>? PluginLoaded
Event Type
PluginUnloaded
Event raised when a plugin is unloaded.
public event EventHandler<PluginEventArgs>? PluginUnloaded
Event Type
ServiceRegistered
Event raised when a service is registered.
public event EventHandler<ServiceRegisteredEventArgs>? ServiceRegistered
Event Type
ServiceUnregistered
Event raised when a service is unregistered.
public event EventHandler<ServiceUnregisteredEventArgs>? ServiceUnregistered
Event Type
StateChanged
Event raised when the plugin state changes.
public event EventHandler<PluginStateChangedEventArgs>? StateChanged