ScriptRunner.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.
- Plugin Metadata: Annotate plugins with
[PluginMetadata]
for easy discovery and validation. - Version & Framework Constants: Ensure compatibility with
PluginSystemConstants
. - Dynamic Plugin Management: Discover, validate, and load plugins using
IPluginLoader
andDependencyLoader
. - Database Utilities: Use
IDatabase
for executing SQL queries andSqlGenerator
for dynamic SQL generation. - Local Storage: Store plugin data with
ILocalStorage
for runtime use and persistence. - Simplified Development: Use base classes like
BasePlugin
andBaseServicePlugin
to reduce boilerplate code. - Plugin Template: Quickly scaffold a new plugin project using the provided template.
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:
- Example plugin class (
Plugin.cs
) using[PluginMetadata]
. - Pre-configured
PluginSystemConstants
for versioning. - Example service registration with
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);
- Use
IDatabase
for database interaction. - Use
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.