In this repository, there is a project integrated with the WorkflowEngine and featuring the implementation of dynamic plugin loading. This code serves as an example of following the tutorial outlined in the documentation.
In this tutorial, we'll implement dynamic plugin loading. This allows you to customize the Workflow Engine
by placing compiled DLLs with plugins into the plugins folder. Plugins are classes that implement IWorkflowPlugin
,
enabling the engine to incorporate new Actions, Rules, etc. Learn more about plugins.
You might be interested in this functionality for a variety of reasons:
- You distribute your software with a Workflow Engine to your clients and want to provide them with customization options without needing access to the source code.
- You want to separate dependencies used in the project with the Workflow Engine from those used for plugins.
- You manage a large number of plugins and want to simplify their modification or installation.
- Application with integrated Workflow Engine.
- IDE for working with C# code, such as Visual Studio.
In this tutorial, we'll step through implementing dynamic plugin loading, which requires:
- Writing a
PluginLoader
class for dynamically loading assemblies. - Adding an extension method for loading plugins into the
WorkflowRuntime
. - Creating a new project with plugin implementation and exporting its DLL.
- Testing and ensuring everything works well.
This class will inherit from the System class AssemblyLoadContext
, aiming to correctly load DLLs and resolve
their dependencies at the specified path.
Go to the code >PluginLoader.cs
The extension method allows us to add dynamic loading of plugins into the Workflow Engine Runtime initialization pipeline alongside other settings.
To test the functionality, we need to create a test project from which we'll import plugins into the Workflow Engine. This requires several steps:
- Create a new project
MyPlugin
.dotnet new classlib --name MyPlugin dotnet sln add MyPlugin rm MyPlugin\Class1.cs
- Add a package reference to
WorkflowEngine.NETCore-Core
to implementIWorkflowPlugin
.dotnet add MyPlugin package WorkflowEngine.NETCore-Core
- Add a new class
MyPlugin
implementing theIWorkflowPlugin
interface. Go to the code >MyPlugin.cs - Build the project and copy its DLL to the
plugins/{plugin_name}/…
folder.dotnet build mkdir -p DynamicPluginLoading/bin/Debug/net8.0/plugins/MyPlugin cp -r MyPlugin/bin/Debug/net8.0/* DynamicPluginLoading/bin/Debug/net8.0/plugins/MyPlugin/
Finally, we have the ability to connect dynamic plugin loading to the WorkflowRuntime creation pipeline with the plugin name specified.
var runtime = new WorkflowRuntime()
.WithPlugin(new BasicPlugin())
// &att>
.WithDynamicPlugins("MyPlugin")
// <&att
.AsSingleServer();
If you've followed the steps exactly, MyPlugin
will appear among the plugins in WorkflowRuntime
,
which you can verify by checking WorkflowRuntime.Plugins
.
foreach (var plugin in runtime.Plugins)
{
Console.WriteLine($"- {plugin.Name}");
}
// Output:
// - BasicPlugin
// - MyPlugin
Now you can easily enhance plugin management in your project.