ScriptRunner.Plugins 1.0.18

Suggested Alternatives

ScriptRunner.Plugins 1.6.12

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ScriptRunner.Plugins --version 1.0.18
                    
NuGet\Install-Package ScriptRunner.Plugins -Version 1.0.18
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ScriptRunner.Plugins" Version="1.0.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ScriptRunner.Plugins" Version="1.0.18" />
                    
Directory.Packages.props
<PackageReference Include="ScriptRunner.Plugins" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ScriptRunner.Plugins --version 1.0.18
                    
#r "nuget: ScriptRunner.Plugins, 1.0.18"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ScriptRunner.Plugins@1.0.18
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ScriptRunner.Plugins&version=1.0.18
                    
Install as a Cake Addin
#tool nuget:?package=ScriptRunner.Plugins&version=1.0.18
                    
Install as a Cake Tool

ScriptRunner.Plugins

NuGet NuGet Downloads License

ScriptRunner.Plugins provides core interfaces, attributes, and utilities for building and integrating plugins into the ScriptRunner framework. It simplifies plugin development and ensures compatibility with the ScriptRunner ecosystem.


Features

  • Plugin Metadata Attribute: Add metadata to your plugin classes using [PluginMetadata].
  • Dependency Injection Support: Register plugin services into the DI container with IServicePlugin.
  • Plugin Dependencies: Declare and validate dependencies between plugins.
  • Plugin System Versioning: Automatically validate plugin compatibility with the current plugin system version.
  • Dynamic Plugin Discovery: Discover and validate plugins at runtime with IPluginLoader.
  • Custom Initialization: Implement initialization and execution logic with IPlugin or BasePlugin.

Installation

Install the NuGet package using the .NET CLI or Package Manager in Visual Studio:

dotnet add package ScriptRunner.Plugins

Usage

Creating a Plugin

  1. Define a Plugin Class: Annotate your class with [PluginMetadata] to provide details like the name, description, version, and system compatibility.

    using ScriptRunner.Plugins.Attributes;
    using ScriptRunner.Plugins.Interfaces;
    
    [PluginMetadata(
        name: "ExamplePlugin",
        description: "A sample plugin for ScriptRunner",
        author: "Your Name",
        version: "1.0.0",
        pluginSystemVersion: "1.0.4",
        frameworkVersion: "net8.0")]
    public class ExamplePlugin : IPlugin
    {
        public string Name => "ExamplePlugin";
    
        public void Initialize(IDictionary<string, object> configuration)
        {
            Console.WriteLine("ExamplePlugin initialized.");
        }
    
        public void Execute()
        {
            Console.WriteLine("ExamplePlugin executed.");
        }
    }
    
  2. Register Services (Optional): If your plugin provides services, implement IServicePlugin and register them in the DI container.

    using Microsoft.Extensions.DependencyInjection;
    
    public class ExamplePlugin : IServicePlugin
    {
        public string Name => "ExamplePlugin";
    
        public void Initialize(IDictionary<string, object> configuration)
        {
            Console.WriteLine("ExamplePlugin initialized.");
        }
    
        public void Execute()
        {
            Console.WriteLine("ExamplePlugin executed.");
        }
    
        public void RegisterServices(IServiceCollection services)
        {
            services.AddSingleton<IMyService, MyService>();
        }
    }
    
  3. Handle Dependencies: If your plugin depends on other plugins, declare them using the Dependencies field in PluginMetadata.

    [PluginMetadata(
        name: "ReportPlugin",
        description: "Generates reports.",
        author: "Your Name",
        version: "1.0.0",
        pluginSystemVersion: "1.0.4",
        dependencies: new[] { "DatabasePlugin", "LoggingPlugin" })]
    public class ReportPlugin : IServicePlugin
    {
        public string Name => "ReportPlugin";
    
        public void RegisterServices(IServiceCollection services)
        {
            services.AddSingleton<IReportService, ReportService>();
        }
    
        public void Initialize(IDictionary<string, object> configuration) { }
        public void Execute() { }
    }
    

Simplify Development with Base Classes

The framework includes several base classes to simplify plugin development. These classes provide default implementations of common plugin interfaces, reducing boilerplate and allowing you to focus on your plugin's core functionality.

Example: BasePlugin

The BasePlugin class implements the IPlugin interface with default behavior for initialization (Initialize) and execution (Execute).

using ScriptRunner.Plugins;

public class MyPlugin : BasePlugin
{
    public override string Name => "MyPlugin";

    public override void Initialize(IDictionary<string, object> configuration)
    {
        Console.WriteLine("MyPlugin initialized.");
    }

    public override void Execute()
    {
        Console.WriteLine("MyPlugin executed.");
    }
}
Comparison of Base Classes
Base Class Implements Key Features
BasePlugin IPlugin Basic plugin with Initialize and Execute methods.
BaseServicePlugin IServicePlugin Adds RegisterServices for DI integration.
BaseAsyncPlugin IAsyncPlugin Async versions of Initialize and Execute.
BaseAsyncServicePlugin IAsyncServicePlugin Async versions of RegisterServices, Initialize, and Execute.
BaseLifecyclePlugin ILifecyclePlugin Adds lifecycle methods (OnStart, OnStop, OnDispose).
BaseGamePlugin IGamePlugin, ILifecyclePlugin Adds frame-based methods (Update and Render) for game development.

Loading Plugins in ScriptRunner

  1. Discover and Validate Plugins: Use IPluginLoader to discover and validate plugins dynamically.

    using System.Reflection;
    using ScriptRunner.Plugins.Utilities;
    
    var pluginLoader = new PluginLoader(new PluginValidator());
    var plugins = pluginLoader.DiscoverAndValidatePlugins(Assembly.Load("YourPluginAssembly"));
    
    foreach (var pluginType in plugins)
    {
        Console.WriteLine($"Discovered plugin: {pluginType.Name}");
    }
    
  2. Use Plugins: Instantiate and execute plugins after validation.

    foreach (var pluginType in plugins)
    {
        var plugin = (IPlugin)Activator.CreateInstance(pluginType)!;
        plugin.Initialize(new Dictionary<string, object>());
        plugin.Execute();
    }
    

Extensibility

  1. Custom Validators: Create a custom implementation of IPluginValidator to apply stricter validation rules.

    public class CustomPluginValidator : IPluginValidator
    {
        public void Validate(Type pluginType)
        {
            // Custom validation logic
        }
    }
    
  2. Custom Loaders: Implement IPluginLoader for specialized plugin discovery mechanisms.

    public class CustomPluginLoader : IPluginLoader
    {
        public IEnumerable<Type> DiscoverAndValidatePlugins(Assembly assembly)
        {
            // Custom plugin discovery and validation logic
        }
    
        public IEnumerable<Type> DiscoverPlugins(Assembly assembly)
        {
            // Custom plugin discovery logic
        }
    }
    

Contributing

Contributions are welcome! If you find a bug or have a feature request, open an issue or submit a pull request on GitHub.


License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.74 322 5/13/2025
1.8.72 207 3/12/2025
1.8.70 181 2/12/2025
1.8.68 154 1/23/2025
1.8.66 144 1/23/2025
1.8.64 151 1/23/2025
1.8.62 152 1/22/2025
1.8.60 151 1/21/2025
1.8.58 163 1/21/2025
1.8.56 108 1/15/2025