ScheduleTaskHelper.Plugins
1.0.7
dotnet add package ScheduleTaskHelper.Plugins --version 1.0.7
NuGet\Install-Package ScheduleTaskHelper.Plugins -Version 1.0.7
<PackageReference Include="ScheduleTaskHelper.Plugins" Version="1.0.7" />
<PackageVersion Include="ScheduleTaskHelper.Plugins" Version="1.0.7" />
<PackageReference Include="ScheduleTaskHelper.Plugins" />
paket add ScheduleTaskHelper.Plugins --version 1.0.7
#r "nuget: ScheduleTaskHelper.Plugins, 1.0.7"
#:package ScheduleTaskHelper.Plugins@1.0.7
#addin nuget:?package=ScheduleTaskHelper.Plugins&version=1.0.7
#tool nuget:?package=ScheduleTaskHelper.Plugins&version=1.0.7
ScheduleTaskHelper.Plugins
?? Overview
ScheduleTaskHelper.Plugins is a plugin-based architecture framework designed for .NET applications. It provides dynamic loading and management of external plugins, enabling developers to extend functionality without modifying the core application. This framework supports plugin initialization, service registration, task management, and graceful unloading, making it ideal for applications requiring high modularity and extensibility.
??? Key Features
- Dynamic Plugin Loading: Load and manage plugins dynamically at runtime.
- Task Scheduling: Support for scheduled and cron-based tasks.
- Dependency Injection: Seamless integration with .NET's DI container.
- Extensibility: Easily extend the application by adding new plugins.
- Task Metadata: Define and manage task metadata, including descriptions, parameters, and execution settings.
- Graceful Shutdown: Ensure proper resource cleanup when unloading plugins.
??? Architecture
Core Components
1. Plugin Interface (IPlugin
)
Defines the contract for all plugins, including methods for initialization, service registration, task retrieval, and shutdown.
public interface IPlugin
{
IPluginMetadata Metadata { get; }
Task<bool> InitializeAsync(IServiceCollection services);
void RegisterServices(IServiceCollection services);
IEnumerable<PluginTaskInfo> GetAvailableTasks();
Task ShutdownAsync();
}
2. Base Plugin (BasePlugin
)
Provides a default implementation of the IPlugin
interface, simplifying plugin development.
3. Plugin Metadata (IPluginMetadata
)
Stores metadata about a plugin, such as its ID, name, version, author, and description.
4. Plugin Task Info (PluginTaskInfo
)
Encapsulates information about tasks provided by a plugin, including task type, ID, description, and default parameters.
5. Plugin Configuration (PluginConfiguration
)
Manages plugin and task configurations, including enabling/disabling plugins and defining task parameters.
6. Plugin Loader (PluginLoader
)
Handles the discovery, loading, and management of plugins.
?? Configuration
Plugin Configuration File (pluginconfig.json
)
Defines the enabled plugins and their task configurations.
{
"EnabledPlugins": [
"SamplePlugin"
],
"TaskConfigurations": {
"SampleTask": {
"Enabled": true,
"Group": "SampleTasks",
"Priority": 1,
"InitialDelay": "00:00:10",
"Period": "00:05:00"
},
"SampleCronTask": {
"Enabled": true,
"Group": "SampleTasks",
"CronExpression": "0 */5 * * * *",
"ExecuteImmediately": true
}
}
}
Key Configuration Fields
- EnabledPlugins: List of plugin IDs to load.
- TaskConfigurations: Defines task-specific settings, such as schedule, priority, and parameters.
?? Getting Started
1. Create a Plugin
Implement the IPlugin
interface or extend the BasePlugin
class to create a new plugin.
public class SamplePlugin : BasePlugin
{
public override IPluginMetadata Metadata => new PluginMetadata(
id: "SamplePlugin",
name: "Sample Plugin",
version: "1.0.0",
author: "Your Name",
description: "A sample plugin demonstrating the plugin architecture."
);
public override IEnumerable<PluginTaskInfo> GetAvailableTasks()
{
yield return new PluginTaskInfo
{
TaskType = typeof(SampleTask),
TaskId = "SampleTask",
DisplayName = "Sample Task",
Description = "A sample task provided by the Sample Plugin.",
EnabledByDefault = true
};
}
}
2. Register Plugin Services
Override the RegisterServices
method to register services required by the plugin.
public override void RegisterServices(IServiceCollection services)
{
services.AddSingleton<ISampleService, SampleService>();
}
3. Load Plugins
Use the PluginLoader
to discover and load plugins dynamically.
var pluginLoader = new PluginLoader();
await pluginLoader.LoadPluginsAsync();
?? API Documentation
Plugin Metadata (IPluginMetadata
)
- Id: Unique identifier for the plugin.
- Name: Display name of the plugin.
- Version: Plugin version.
- Author: Plugin author.
- Description: Description of the plugin.
Plugin Task Info (PluginTaskInfo
)
- TaskType: Type of the task (must implement
IScheduledTask
orICronScheduledTask
). - TaskId: Unique identifier for the task.
- DisplayName: Display name of the task.
- Description: Description of the task.
- DefaultParameters: Default parameters for the task.
- EnabledByDefault: Indicates if the task is enabled by default.
?? License
This project is licensed under the MIT License. See the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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. |
-
net7.0
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- ScheduleTaskHelper.Infrastructure (>= 1.0.7)
- ScheduleTaskHelper.Tasks (>= 1.0.7)
-
net8.0
- Microsoft.Extensions.Configuration.Binder (>= 9.0.8)
- Microsoft.Extensions.Configuration.Json (>= 9.0.8)
- ScheduleTaskHelper.Infrastructure (>= 1.0.7)
- ScheduleTaskHelper.Tasks (>= 1.0.7)
-
net9.0
- Microsoft.Extensions.Configuration.Binder (>= 9.0.8)
- Microsoft.Extensions.Configuration.Json (>= 9.0.8)
- ScheduleTaskHelper.Infrastructure (>= 1.0.7)
- ScheduleTaskHelper.Tasks (>= 1.0.7)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ScheduleTaskHelper.Plugins:
Package | Downloads |
---|---|
ScheduleTaskHelper.Core
ScheduleTaskHelper 是一個功能強大的任務排程與執行框架,專為 .NET 應用程式設計。它支援多種任務排程模式(包括定時與 Cron 表達式),並整合了分散式鎖機制、任務重試佇列與事件驅動架構,確保任務執行的可靠性與高效性。此外,該框架支援插件式架構,允許動態載入外部插件,適合用於分散式系統或需要高效任務管理的應用場景。 |
GitHub repositories
This package is not used by any popular GitHub repositories.