A plugin architecture remains a valuable option to make your application extensible. With the introduction of AssemblyLoadContext and AssemblyDependencyResolver in
.NET Core 3, creating and loading plugins became a lot easier.
Still if you need more features I would recommend having a look at the DotNetCorePlugins project: https://github.com/natemcmaster/DotNetCorePlugins
Usage is simple through the PluginLoader class:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PluginLoader.CreateFromAssemblyFile( | |
assemblyFile: "./plugins/MyPlugin/MyPlugin1.dll", | |
sharedTypes: new [] { typeof(IPlugin), typeof(IServiceCollection), typeof(ILogger) }, | |
isUnloadable: true) |
One nice feature it adds to the mix is hot reloading. This will allow you to dynamically update assemblies on the fly:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loader = PluginLoader.CreateFromAssemblyFile("./plugins/MyPlugin/MyPlugin1.dll", | |
config => config.EnableHotReload = true); | |
loader.Reloaded += ShowPluginInfo; | |
private void ShowPluginInfo(object sender, PluginReloadedEventArgs eventArgs) | |
{ | |
} |