Plumsy is a library for plugin management in C#. It is capable of inspecting and validating dlls, before loading them into the current AppDomain.
Plumsy offers a set of extensions and callbacks to allow the caller to configure what plugins to load, how to handle plugin dependencies and runtime differences.
var pluginManager = new PluginManager(pathToPlugins);
var availablePlugins = pluginManager.GetAvailablePlugins();
Plumsy will call the validators for each of the dlls found in the pathToPlugins
and validate the metadata of those dlls. If the dlls pass the validation, they are marked as available and returned by the above call.
var results = pluginManager.LoadPlugins(availablePlugins);
Plumsy will attempt to load the provided list of plugin entries into the current AppDomain. results
is a list of PluginLoadOperation
, the type depending on the result of the load operation.
PluginLoadOperation.Success
contains a reference to the loaded assembly and implies that the plugin has been loaded successfully.PluginLoadOperation.NullEntry
implies that the plugin entry was null.PluginLoadOperation.FileNotFound
implies that the plugin path was not found.PluginLoadOperation.ExceptionEncountered
implies that the plugin failed to load due to an exception. Check the innerException
property for details.PluginLoadOperation.UnexpectedErrorOccurred
implies that an unexpected error occurred. This happens when theAssembly.Load
call succeeds but the returned assembly isnull
.
pluginManager
.WithEnvironmentVersionValidator(environmentVersionValidator)
.WithMetadataValidator(metadataValidator)
.WithTypeDefinitionsValidator(typeDefinitionsValidator);
environmentVersionValidator
is of typeIEnvironmentVersionValidator
. This validator is used to validate theVersion
of the current runtime in comparison to the plugin target runtime.metadataValidator
is of typeIMetadataValidator
. This validator receives a reference to theMetadataReader
and can perform general validations over the plugin.typeDefinitionsValidator
is of typeITypeDefinitionsValidator
. This validator receives a reference to theMetadataReader
as well as a list ofType
s in order to perform validations over the plugin. This is useful when wanting to validate that the plugin contains a specific entry point class of a known type.
pluginManager
.WithAssemblyLoadedCallback(assemblyLoadedCallback);
assemblyLoadedCallback
is of typeIAssemblyLoadedCallback
. This callback is called after an assembly has been loaded into the current AppDomain.
pluginManager
.WithDependencyResolver(dependencyResolver);
dependencyResolver
is of typeIDependencyResolver
. The dependency solver is called when the runtime is unable to find some dependencies of the currently loading plugin. !! Due to the runtime lazily loading types, dependencies might only be resolved when calling specific methods !!
pluginManager
.WithForceLoadDependencies(true|false);
- When forcing the Plumsy to load dependencies, Plumsy will attempt to manually cause JIT-ing of the methods in the loaded assembly. This would in turn cause the runtime to load its dependencies and would trigger
IDependencyResolver.TryResolveDependency
in cases where a dependency is not found. - By default, Plumsy forces dependencies to load on assembly load. If you want instead to lazily load dependencies, call
pluginManager.WithForceLoadDependencies(false)
.