How to create a dynamic plugin
From OpenSimulator
Current state of Plugin loading
The .NET runtime system has always made reflecting and introspecting of assemblies at runtime very easy to do, making dynamic loading of modules possible with very little effort.
This has unfortunately lead to a situation in OpenSim where historically module loading was hard-coded and done by hand, using copy-and-paste code. Clearly this is a suboptimal situation.
Effort was made to find a reusable, cross-platform dynamic assembly loader that could be used as-is, instead of reinventing our own. The only current candidate is Mono.Addins. MS's .NET runtime has its own Addin class, however it is not yet implemented in Mono.
A class called PluginLoader has been created to thinly wrap Mono.Addins, and the assemblies loaded by this class have been standardized on the IPlugin interface hierarchy. With the exception of RegionModules, all dynamically loaded assemblies should be called Plugins, and inherit from this base class.
Currently the following interfaces have been converted to IPlugin:
- OpenSim.Region.Application.IApplicationPlugin
- OpenSim.Grid.GridServer.IGridPlugin
- OpenSim.Data.IGridDataPlugin
- OpenSim.Data.ILogDataPlugin
And the following Assemblies are being loaded by PluginLoader:
- OpenSim.ApplicationPlugins.LoadRegions.LoadRegionsPlugin
- OpenSim.ApplicationPlugins.Rest.Regions.RestRegionPlugin
- OpenSim.ApplicationPlugins.Rest.Inventory.RestHandler
- OpenSim.ApplicationPlugins.RemoteController.RemoteAdminPlugin
- OpenSim.Data.MySQL.MySQLGridData
- OpenSim.Data.MySQL.MySQLLogData
Mono.Addins offers features outside of being upstream maintained by the Mono project:
- logically splits up module interfaces from implementations in a cross platform way through the use of text-based "extension points" and "addin manifests"
- automatically handles module sharing across application domains
- provides support for downloading assemblies from remote repositories