DevelApp.RuntimePluggableClassFactory
2.0.1
dotnet add package DevelApp.RuntimePluggableClassFactory --version 2.0.1
NuGet\Install-Package DevelApp.RuntimePluggableClassFactory -Version 2.0.1
<PackageReference Include="DevelApp.RuntimePluggableClassFactory" Version="2.0.1" />
<PackageVersion Include="DevelApp.RuntimePluggableClassFactory" Version="2.0.1" />
<PackageReference Include="DevelApp.RuntimePluggableClassFactory" />
paket add DevelApp.RuntimePluggableClassFactory --version 2.0.1
#r "nuget: DevelApp.RuntimePluggableClassFactory, 2.0.1"
#:package DevelApp.RuntimePluggableClassFactory@2.0.1
#addin nuget:?package=DevelApp.RuntimePluggableClassFactory&version=2.0.1
#tool nuget:?package=DevelApp.RuntimePluggableClassFactory&version=2.0.1
RuntimePluggableClassFactory
A comprehensive .NET library for dynamic plugin loading, execution, and management with enhanced stability, type safety, and security features.
🚀 TDS Implementation Complete
This project has been enhanced with a complete Technical Design Specification (TDS) implementation featuring:
- ✅ Dynamic Plugin Loading/Unloading with AssemblyLoadContext
- ✅ Enhanced Stability with comprehensive error handling
- ✅ Type Safety with strongly-typed plugin interfaces
- ✅ Security Hardening with multi-level validation
- ✅ Comprehensive Testing with 48 tests across 7 categories
See TDS_IMPLEMENTATION.md for complete implementation details.
Features
Core Capabilities
- Dynamic plugin discovery and loading from directories
- Runtime plugin unloading with proper memory cleanup
- Version-aware plugin management
- Thread-safe concurrent plugin execution
- Comprehensive error handling and recovery
Type Safety
- Generic plugin interfaces:
ITypedPluginClass<TInput, TOutput>
- Strongly-typed DTOs for plugin communication
- Execution context with logging and cancellation support
- Type-safe plugin discovery and execution
Security
- Multi-level security validation (assembly, type, method)
- Configurable security policies (Default, Strict, Permissive)
- Digital signature verification
- Trusted path validation
- Prohibited namespace and type detection
Performance
- High-throughput concurrent execution (>100 exec/sec)
- Fast plugin instantiation (<100ms average)
- Efficient memory management with unloading
- Performance monitoring and validation
Quick Start
Basic Usage
using DevelApp.RuntimePluggableClassFactory;
using DevelApp.RuntimePluggableClassFactory.FilePlugin;
using DevelApp.RuntimePluggableClassFactory.Security;
// Create plugin loader with security validation
var securityValidator = new DefaultPluginSecurityValidator(PluginSecuritySettings.CreateDefault());
var pluginLoader = new FilePluginLoader<IMyPluginInterface>(pluginDirectory, securityValidator);
var pluginFactory = new PluginClassFactory<IMyPluginInterface>(pluginLoader);
// Load and execute plugins
await pluginFactory.RefreshPluginsAsync();
var plugin = pluginFactory.GetInstance("MyModule", "MyPlugin");
var result = plugin.Execute("input data");
// Cleanup
pluginLoader.UnloadAllPlugins();
Type-Safe Usage
// Define strongly-typed input/output
public class MyInput { public string Data { get; set; } }
public class MyOutput { public string Result { get; set; } }
// Create typed plugin factory
var typedFactory = new TypedPluginClassFactory<IMyTypedPlugin, MyInput, MyOutput>(pluginLoader);
// Execute with type safety
var input = new MyInput { Data = "test" };
var result = typedFactory.ExecutePlugin("MyModule", "MyPlugin", input);
if (result.Success)
{
Console.WriteLine($"Result: {result.Data.Result}");
}
Plugin Development
Basic Plugin Interface
public interface IMyPluginInterface : IPluginClass
{
// Inherits: string Execute(string input);
}
public class MyPlugin : IMyPluginInterface
{
public string Execute(string input)
{
return $"Processed: {input}";
}
}
Type-Safe Plugin Interface
public interface IMyTypedPlugin : ITypedPluginClass<MyInput, MyOutput>
{
// Inherits both IPluginClass and ITypedPluginClass methods
}
public class MyTypedPlugin : IMyTypedPlugin
{
public string Execute(string input) => Execute(JsonSerializer.Deserialize<MyInput>(input)).Data.Result;
public PluginExecutionResult<MyOutput> Execute(MyInput input, IPluginExecutionContext context = null)
{
context?.Logger?.LogInformation($"Processing: {input.Data}");
return PluginExecutionResult<MyOutput>.CreateSuccess(new MyOutput
{
Result = $"Processed: {input.Data}"
});
}
}
Testing
The project includes comprehensive testing with 48 tests across 7 categories:
# Run all tests
dotnet test
# Expected: 48 tests passing
Test Categories
- Unit Tests (8) - Core functionality
- Stability Tests (3) - Error handling
- Unloading Tests (2) - Dynamic unloading
- Typed Plugin Tests (6) - Type safety
- Security Tests (13) - Security validation
- Integration Tests (8) - End-to-end workflows
- Performance Tests (8) - Performance benchmarks
Security
Security Policies
// Default security (balanced)
var defaultSettings = PluginSecuritySettings.CreateDefault();
// Strict security (high security)
var strictSettings = PluginSecuritySettings.CreateStrict();
// Permissive security (minimal restrictions)
var permissiveSettings = PluginSecuritySettings.CreatePermissive();
var validator = new DefaultPluginSecurityValidator(strictSettings);
Security Features
- Assembly size limits and digital signature verification
- Prohibited namespace and type detection
- Dangerous method pattern analysis
- Trusted path validation
- Risk level assessment
Performance Benchmarks
All performance targets are validated by automated tests:
Metric | Target | Status |
---|---|---|
Plugin Discovery | < 5 seconds | ✅ Validated |
Plugin Instantiation | < 100ms avg | ✅ Validated |
Plugin Execution | < 10ms avg | ✅ Validated |
Concurrent Throughput | > 100 exec/sec | ✅ Validated |
Security Validation | < 500ms avg | ✅ Validated |
Memory Growth | < 50MB under load | ✅ Validated |
Architecture
Core Components
- PluginLoadContext: Collectible AssemblyLoadContext for proper unloading
- FilePluginLoader: File-based plugin discovery and loading
- PluginClassFactory: Core plugin factory with error handling
- TypedPluginClassFactory: Type-safe plugin execution
- PluginExecutionSandbox: Isolated execution environment
- DefaultPluginSecurityValidator: Comprehensive security validation
Key Interfaces
IPluginClass
: Basic plugin interfaceITypedPluginClass<TInput, TOutput>
: Type-safe plugin interfaceIPluginLoader<T>
: Plugin loading interfaceIPluginSecurityValidator
: Security validation interface
Documentation
- TDS Implementation Details - Complete TDS implementation documentation
- Testing Strategy - Comprehensive testing approach
- Architecture Analysis - Technical architecture details
Requirements
- .NET 8.0 or later
- xUnit (for testing)
- Compatible with Windows, Linux, and macOS
Installation
# Clone repository
git clone https://github.com/DevelApp-dk/RuntimePluggableClassFactory.git
# Build solution
dotnet build RuntimePluggableClassFactory.sln
# Run tests
dotnet test
Why Use RuntimePluggableClassFactory
Original Use Cases (Still Supported)
- Websites/APIs without persisted session state: Avoid session loss during dependency injection reloads
- Separating frequently modified extensions: Enable runtime loading and replacement without application restart
- A/B testing for services: Load different plugin versions for testing
- Fault isolation: Plugin errors don't crash the entire application
- Easier testing: Test extensions separately from other concerns
Enhanced TDS Capabilities
- Dynamic Plugin Management: Load and unload plugins without application restart
- Type Safety: Strongly-typed plugin interfaces eliminate runtime type errors
- Security Hardening: Multi-level validation prevents malicious plugin execution
- Performance Optimization: High-throughput concurrent execution with memory management
- Comprehensive Testing: 48 automated tests ensure reliability and performance
Contributing
- Fork the repository
- Create a feature branch
- Implement changes with tests
- Ensure all 48 tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions, issues, or support:
- Review the comprehensive test suite (48 tests)
- Check the TDS Implementation Guide
- Examine the Testing Strategy
- Create an issue on GitHub
TDS Implementation Status: ✅ Complete - All requirements implemented and validated
Test change
Product | Versions 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. |
-
net8.0
- DevelApp.RuntimePluggableClassFactory.Interface (>= 2.0.1)
- develapp.utility (>= 1.0.7)
- System.Runtime.Loader (>= 4.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DevelApp.RuntimePluggableClassFactory:
Package | Downloads |
---|---|
DevelApp.Workflow.AutoFac
Setup for AutoFac for DevelApp.Workflow DevelApp.Workflow which is an oppinionated Workflow for Akka.Net making it easy to handle workflows |
GitHub repositories
This package is not used by any popular GitHub repositories.
TDS Implementation Complete:
- Dynamic plugin loading/unloading with AssemblyLoadContext
- Enhanced stability with comprehensive error handling
- Type safety with strongly-typed plugin interfaces (ITypedPluginClass<TInput, TOutput>)
- Security hardening with multi-level validation and configurable policies
- Comprehensive testing with 48 tests across 7 categories
- Performance benchmarks: <100ms instantiation, >100 exec/sec throughput
- Runtime plugin detection and hot-swapping capabilities
- Plugin execution sandboxing for isolation
- Backward compatible with existing IPluginClass implementations