A plugin framework for ScriptRunner
$ dotnet add package ScriptRunner.PluginsScriptRunner.Plugins provides interfaces, attributes, utilities, and constants for building plugins compatible with
the ScriptRunner framework. It ensures seamless plugin development with dynamic loading, validation, and integration.
[PluginMetadata] for easy discovery and validation.PluginSystemConstants.IPluginLoader and DependencyLoader.IDatabase for executing SQL queries and SqlGenerator for dynamic SQL generation.ILocalStorage for runtime use and persistence.BasePlugin and BaseServicePlugin to reduce boilerplate code.Install via NuGet:
dotnet add package ScriptRunner.Plugins
The ScriptRunner.Plugins package includes a template to help you quickly set up a plugin project. Use the dotnet new
command:
dotnet new srplugin -n MyNewPlugin
This creates a project with:
Plugin.cs) using [PluginMetadata].PluginSystemConstants for versioning.IServicePlugin.Define your plugin class and use [PluginMetadata] for metadata:
using ScriptRunner.Plugins.Attributes;
using ScriptRunner.Plugins.Utilities;
[PluginMetadata(
name: "SamplePlugin",
description: "A simple plugin example.",
author: "Your Name",
version: "1.0.0",
pluginSystemVersion: PluginSystemConstants.CurrentPluginSystemVersion,
frameworkVersion: PluginSystemConstants.CurrentFrameworkVersion)]
public class SamplePlugin : IPlugin
{
public void Initialize(IDictionary<string, object> configuration) => Console.WriteLine("Initialized.");
public void Execute() => Console.WriteLine("Executed.");
}
Register services if needed:
public class SampleServicePlugin : IServicePlugin
{
public void RegisterServices(IServiceCollection services)
{
services.AddSingleton<IMyService, MyService>();
}
}
Use PluginSystemConstants to ensure host and plugin version compatibility:
public static class PluginSystemConstants
{
public const string CurrentPluginSystemVersion = "1.2.0";
public const string CurrentFrameworkVersion = ".NET 8.0";
}
Load dependencies dynamically with DependencyLoader:
DependencyLoader.SetSkipLibraries(new[] { "sqlite3.dll" });
DependencyLoader.LoadDependencies("path/to/dependencies", new ConcurrentDictionary<string, bool>(), logger);
IDatabase for database interaction.SqlGenerator for generating queries dynamically:var generator = new SqlGenerator();
generator.SetType(typeof(MyEntity));
generator.SetTableName("MyTable");
var query = generator.GenerateSelectQuery();
Use ILocalStorage for temporary data storage and persistence:
var storage = new LocalStorage();
storage.SetData("key", "value");
storage.SaveToFile("storage.json");
storage.LoadFromFile("storage.json");
Use base classes like BasePlugin or BaseAsyncServicePlugin to minimize repetitive code.
Example with BasePlugin:
public class MyPlugin : BasePlugin
{
public override void Initialize(IDictionary<string, object> configuration) => Console.WriteLine("Initialized.");
public override void Execute() => Console.WriteLine("Executed.");
}
Contributions are welcome! Submit issues or PRs on GitHub.
This project is licensed under the MIT License.