Ejemplo n.º 1
0
        private static AssemblyLoadContext CreateLoadContext(ModuleLoaderConfig config)
        {
            var builder = new AssemblyLoadContextBuilder();

            builder.SetMainAssemblyPath(config.MainAssemblyPath);

            foreach (var ext in config.PrivateAssemblies)
            {
                builder.PreferLoadContextAssembly(ext);
            }

            if (config.PreferSharedTypes)
            {
                builder.PreferDefaultLoadContext(true);
            }

            if (config.IsUnloadable)
            {
                builder.EnableUnloading();
            }

            foreach (var assemblyName in config.SharedAssemblies)
            {
                builder.PreferDefaultLoadContextAssembly(assemblyName);
            }

            return(builder.Build());
        }
Ejemplo n.º 2
0
        public static PluginLoader CreateFromAssemblyFile(string assemblyFile, Action <ModuleLoaderConfig> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var config = new ModuleLoaderConfig(assemblyFile);

            configure(config);
            return(new PluginLoader(config));
        }
Ejemplo n.º 3
0
 public PluginLoader(ModuleLoaderConfig config)
 {
     _config   = config ?? throw new ArgumentNullException(nameof(config));
     _context  = CreateLoadContext(config);
     Reference = new WeakReference(_context, true);
 }