Overview
Silky's plugin system allows you to load additional modules from external assemblies at runtime, without compiling them into the main host project. This enables:
- Hot-loadable extension packs
- Optional feature modules
- Separation of concerns in large codebases
- Third-party extensions
Plugin Configuration
Specify plugin directories in appsettings.json:
{
"plugin": {
"path": "plugins",
"enable": true
}
}
At startup, Silky scans the specified directory for plugin assemblies and loads all valid SilkyModule subclasses found.
Creating a Plugin
1. Create a Class Library
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Silky.Core" Version="3.9.2" />
</ItemGroup>
</Project>
2. Define the Plugin Module
using Silky.Core.Modularity;
public class AnalyticsPluginModule : SilkyModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddSingleton<IAnalyticsService, DefaultAnalyticsService>();
context.Services.AddHostedService<AnalyticsBackgroundService>();
}
}
3. Implement Plugin Services
public class DefaultAnalyticsService : IAnalyticsService, ISingletonDependency
{
public void TrackEvent(string eventName, IDictionary<string, object> properties)
{
// ...
}
}
Deploying a Plugin
Build the plugin project:
dotnet publish -c Release -o ./publish/plugins/AnalyticsCopy the output to the host's plugin directory:
{host-root}/ plugins/ Analytics/ AnalyticsPlugin.dll AnalyticsPlugin.deps.jsonRestart the host — the plugin is picked up automatically.
Plugin Dependencies
Plugin assemblies are loaded in isolation. If a plugin depends on packages already loaded by the host, those are shared. If a dependency is unique to the plugin, it must be included in the plugin directory.
Use Cases
| Scenario | Implementation |
|---|---|
| Feature toggle | Load module only when feature flag is enabled |
| Multi-tenant customization | Per-tenant plugin with custom business rules |
| Third-party integrations | Deliver as a plugin package (NuGet → unzip to plugins/) |
| Hot reload (limited) | Restart the host to reload updated plugins |
Tips
Plugin hot reload (without process restart) is not currently supported. Plugins are loaded once at startup.
