Table of Contents

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

string

Capabilities

Gets the plugin's capabilities and features.

public abstract PluginCapabilities Capabilities { get; }

Property Value

PluginCapabilities

Configuration

protected IConfiguration? Configuration { get; }

Property Value

IConfiguration

Description

Gets the description of the plugin.

public abstract string Description { get; }

Property Value

string

Health

Gets the plugin's health status.

public PluginHealth Health { get; protected set; }

Property Value

PluginHealth

Id

Gets the unique identifier for this plugin.

public abstract string Id { get; }

Property Value

string

IsLoaded

Gets whether the plugin is loaded and in a running state.

public bool IsLoaded { get; }

Property Value

bool

Logger

protected ILogger? Logger { get; }

Property Value

ILogger

Name

Gets the display name of the plugin.

public abstract string Name { get; }

Property Value

string

ServiceProvider

protected IServiceProvider? ServiceProvider { get; }

Property Value

IServiceProvider

State

Gets the current state of the plugin.

public PluginState State { get; protected set; }

Property Value

PluginState

Version

Gets the version of the plugin.

public abstract Version Version { get; }

Property Value

Version

Methods

ConfigureServices(IServiceCollection, IConfiguration)

Configures services for dependency injection.

public virtual void ConfigureServices(IServiceCollection services, IConfiguration configuration)

Parameters

services IServiceCollection

The service collection to configure.

configuration IConfiguration

The 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

disposing bool

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

serviceProvider IServiceProvider

The service provider for dependency resolution.

cancellationToken CancellationToken

Cancellation 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

serviceProvider IServiceProvider
cancellationToken CancellationToken

Returns

Task

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

cancellationToken CancellationToken

Returns

Task

OnConfigurationChangedAsync(IConfiguration, CancellationToken)

Handles configuration changes at runtime.

public virtual Task OnConfigurationChangedAsync(IConfiguration configuration, CancellationToken cancellationToken = default)

Parameters

configuration IConfiguration

The new configuration.

cancellationToken CancellationToken

Cancellation 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

configuration IConfiguration
cancellationToken CancellationToken

Returns

Task

OnError(Exception, string)

Raises the ErrorOccurred event.

protected void OnError(Exception exception, string context)

Parameters

exception Exception
context string

OnInitializeAsync(CancellationToken)

Called when the plugin needs to be initialized.

protected virtual Task OnInitializeAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

OnStartAsync(CancellationToken)

Called when the plugin needs to be started.

protected virtual Task OnStartAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

OnStopAsync(CancellationToken)

Called when the plugin needs to be stopped.

protected virtual Task OnStopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

OnUpdateMetrics(PluginMetrics)

Called when metrics need to be updated.

protected virtual void OnUpdateMetrics(PluginMetrics metrics)

Parameters

metrics PluginMetrics

OnValidate(PluginValidationResult)

Called when plugin validation is performed.

protected virtual void OnValidate(PluginValidationResult result)

Parameters

result PluginValidationResult

RecordError()

Records an error.

protected void RecordError()

RecordRequest(double)

Records a successful request.

protected void RecordRequest(double responseTime = 0)

Parameters

responseTime double

SetCustomMetric(string, object)

Sets a custom metric value.

protected void SetCustomMetric(string name, object value)

Parameters

name string
value object

StartAsync(CancellationToken)

Starts the plugin asynchronously.

public virtual Task StartAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation token.

Returns

Task

Task representing the async operation.

StopAsync(CancellationToken)

Stops the plugin asynchronously.

public virtual Task StopAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Cancellation 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

cancellationToken CancellationToken

Returns

Task

UpdateCpuUsage(double)

Updates CPU usage metric.

protected void UpdateCpuUsage(double percentage)

Parameters

percentage double

UpdateMemoryUsage(long)

Updates memory usage metric.

protected void UpdateMemoryUsage(long bytes)

Parameters

bytes long

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

EventHandler<PluginErrorEventArgs>

HealthChanged

Occurs when health changed.

public event EventHandler<PluginHealthChangedEventArgs>? HealthChanged

Event Type

EventHandler<PluginHealthChangedEventArgs>

StateChanged

Occurs when state changed.

public event EventHandler<PluginStateChangedEventArgs>? StateChanged

Event Type

EventHandler<PluginStateChangedEventArgs>