Class BackendPluginBase
- Namespace
- DotCompute.Plugins.Core
- Assembly
- DotCompute.Plugins.dll
Base implementation for backend plugins.
public abstract class BackendPluginBase : IBackendPlugin, IDisposable
- Inheritance
-
BackendPluginBase
- Implements
- Derived
- Inherited Members
- Extension Methods
Properties
Author
Gets the author of the plugin.
public abstract string Author { get; }
Property Value
Capabilities
Gets the plugin's capabilities and features.
public abstract PluginCapabilities Capabilities { get; }
Property Value
Configuration
protected IConfiguration? Configuration { get; }
Property Value
Description
Gets the description of the plugin.
public abstract string Description { get; }
Property Value
Health
Gets the plugin's health status.
public PluginHealth Health { get; protected set; }
Property Value
Id
Gets the unique identifier for this plugin.
public abstract string Id { get; }
Property Value
IsLoaded
Gets whether the plugin is loaded and in a running state.
public bool IsLoaded { get; }
Property Value
Logger
protected ILogger? Logger { get; }
Property Value
Name
Gets the display name of the plugin.
public abstract string Name { get; }
Property Value
ServiceProvider
protected IServiceProvider? ServiceProvider { get; }
Property Value
State
Gets the current state of the plugin.
public PluginState State { get; protected set; }
Property Value
Version
Gets the version of the plugin.
public abstract Version Version { get; }
Property Value
Methods
ConfigureServices(IServiceCollection, IConfiguration)
Configures services for dependency injection.
public virtual void ConfigureServices(IServiceCollection services, IConfiguration configuration)
Parameters
servicesIServiceCollectionThe service collection to configure.
configurationIConfigurationThe configuration for the plugin.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
Releases resources used by the plugin.
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
GetConfigurationSchema()
Gets the plugin's configuration schema.
public virtual string GetConfigurationSchema()
Returns
- string
JSON schema for the plugin's configuration.
GetMetrics()
Gets the plugin's performance metrics.
public virtual PluginMetrics GetMetrics()
Returns
- PluginMetrics
Current performance metrics.
InitializeAsync(IServiceProvider, CancellationToken)
Initializes the plugin asynchronously.
public virtual Task InitializeAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken = default)
Parameters
serviceProviderIServiceProviderThe service provider for dependency resolution.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task representing the async operation.
LoadAsync(IServiceProvider, CancellationToken)
Loads the plugin asynchronously. This method requires a service provider to be passed since it's used before initialization.
public Task LoadAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken = default)
Parameters
serviceProviderIServiceProvidercancellationTokenCancellationToken
Returns
LoadAsync(CancellationToken)
Loads the plugin asynchronously using the already initialized service provider. This overload can only be called after the plugin has been initialized.
public Task LoadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
OnConfigurationChangedAsync(IConfiguration, CancellationToken)
Handles configuration changes at runtime.
public virtual Task OnConfigurationChangedAsync(IConfiguration configuration, CancellationToken cancellationToken = default)
Parameters
configurationIConfigurationThe new configuration.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task representing the async operation.
OnConfigurationUpdatedAsync(IConfiguration, CancellationToken)
Called when configuration is updated.
protected virtual Task OnConfigurationUpdatedAsync(IConfiguration configuration, CancellationToken cancellationToken)
Parameters
configurationIConfigurationcancellationTokenCancellationToken
Returns
OnError(Exception, string)
Raises the ErrorOccurred event.
protected void OnError(Exception exception, string context)
Parameters
OnInitializeAsync(CancellationToken)
Called when the plugin needs to be initialized.
protected virtual Task OnInitializeAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
OnStartAsync(CancellationToken)
Called when the plugin needs to be started.
protected virtual Task OnStartAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
OnStopAsync(CancellationToken)
Called when the plugin needs to be stopped.
protected virtual Task OnStopAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationToken
Returns
OnUpdateMetrics(PluginMetrics)
Called when metrics need to be updated.
protected virtual void OnUpdateMetrics(PluginMetrics metrics)
Parameters
metricsPluginMetrics
OnValidate(PluginValidationResult)
Called when plugin validation is performed.
protected virtual void OnValidate(PluginValidationResult result)
Parameters
resultPluginValidationResult
RecordError()
Records an error.
protected void RecordError()
RecordRequest(double)
Records a successful request.
protected void RecordRequest(double responseTime = 0)
Parameters
responseTimedouble
SetCustomMetric(string, object)
Sets a custom metric value.
protected void SetCustomMetric(string name, object value)
Parameters
StartAsync(CancellationToken)
Starts the plugin asynchronously.
public virtual Task StartAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task representing the async operation.
StopAsync(CancellationToken)
Stops the plugin asynchronously.
public virtual Task StopAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
Task representing the async operation.
ThrowIfDisposed()
Throws if the plugin has been disposed.
protected void ThrowIfDisposed()
UnloadAsync(CancellationToken)
Unloads the plugin asynchronously.
public Task UnloadAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken
Returns
UpdateCpuUsage(double)
Updates CPU usage metric.
protected void UpdateCpuUsage(double percentage)
Parameters
percentagedouble
UpdateMemoryUsage(long)
Updates memory usage metric.
protected void UpdateMemoryUsage(long bytes)
Parameters
byteslong
Validate()
Validates the plugin's configuration and dependencies.
public virtual PluginValidationResult Validate()
Returns
- PluginValidationResult
Validation result with any errors or warnings.
Events
ErrorOccurred
Occurs when error occurred.
public event EventHandler<PluginErrorEventArgs>? ErrorOccurred
Event Type
HealthChanged
Occurs when health changed.
public event EventHandler<PluginHealthChangedEventArgs>? HealthChanged
Event Type
StateChanged
Occurs when state changed.
public event EventHandler<PluginStateChangedEventArgs>? StateChanged