Jump to the main content

Domain API cheat sheet


Member namefunction
LoadPluginBehaviorDecide on the plugin loading strategy:None (default),UseHighVersion ,UseLowVersion,UseBeforeIfExist (skip if one already exists)
LoadPlugin(path,func)Load the plugin and its dependencies, parameter 1: plugin path; Parameter 2: Exclude certain dependencies according to AssemblyName;
LoadPluginWithHighDependencyLoadPlugin-based extension: Load plugin with behavior UseHighVersion
LoadPluginWithLowDependencyLoadPlugin-based extension method: Behavior is UseLowVersionwhen loading plugins
LoadPluginWithNewDependencyLoadPlugin-based extension method: Behavior is None when loading the plugin
LoadPluginSkipDefaultDependencyLoadPlugin-based extension method: Behavior when loading plugins is UseBeforeIfExist
GetPluginAssembliesGets the collection of assemblies that the domain contains
LoadAssemblyFromStreamLoads a stream to the domain and returns the assembly
LoadAssemblyFromFileLoads a file into the domain and returns the assembly
ReferenceCacheReference caching

Use case

initialize:

or
var domain = DomainManagement.Create("myDomain")/Random();
//or
using ("myDomain". NatashaDomainScope()){ var domain = DomainManagement.CurrentDomain; }
//or
using (DomainManagement.Create("myDomain"). CreateScope()){ var domain = DomainManagement.CurrentDomain; }

Plugin loading:

Decide which dll the plugin depends on
domain when it conflicts with the dll loaded by the main domain. LoadPluginBehavior = LoadBehaviorEnum.UseHighVersion;
var assembly = domain. LoadPlugin(dllPath);
var assembly = domain. LoadPlugin(dllPath,item=>item. Contain("xxx"));

//or
domain. LoadPluginWithHighDependency(dllPath,item=>item. StartWith("xxx"));
domain. LoadPluginWithLowDependency(dllPath,item=>item. Name!="xxx");
domain. LoadPluginWithNewDependency(dllPath,item=>true);
domain. LoadPluginSkipDefaultDependency(dllPath);