public async Task CanUseHostsDependencies() { // Make sure that the referenced version of JSON.NET is loaded into memory var json = Newtonsoft.Json.JsonConvert.SerializeObject(1); _testOutputHelper.WriteLine(json); var options = new AssemblyPluginCatalogOptions { PluginLoadContextOptions = new PluginLoadContextOptions() { UseHostApplicationAssemblies = UseHostApplicationAssembliesEnum.Always } }; var folder1Catalog = new AssemblyPluginCatalog(@"..\..\..\..\..\Assemblies\bin\JsonNew\netstandard2.0\JsonNetNew.dll", options); await folder1Catalog.Initialize(); var folder2Catalog = new AssemblyPluginCatalog(@"..\..\..\..\..\Assemblies\bin\JsonOld\netstandard2.0\JsonNetOld.dll", options); await folder2Catalog.Initialize(); var newPlugin = folder1Catalog.Single(); var oldPlugin = folder2Catalog.Single(); dynamic newPluginJsonResolver = Activator.CreateInstance(newPlugin); var newPluginVersion = newPluginJsonResolver.GetVersion(); dynamic oldPluginJsonResolver = Activator.CreateInstance(oldPlugin); var oldPluginVersion = oldPluginJsonResolver.GetVersion(); Assert.Equal("12.0.0.0", newPluginVersion); Assert.Equal("12.0.0.0", oldPluginVersion); }
public async Task CanUseSelectedHoststDependencies() { // Make sure that the referenced version of JSON.NET is loaded into memory var json = Newtonsoft.Json.JsonConvert.SerializeObject(1); // Make sure that the referenced version of Microsoft.Extensions.Logging is loaded into memory var logging = new Microsoft.Extensions.Logging.LoggerFactory(); var options = new AssemblyPluginCatalogOptions();; options.PluginLoadContextOptions = new PluginLoadContextOptions() { UseHostApplicationAssemblies = UseHostApplicationAssembliesEnum.Selected, HostApplicationAssemblies = new List <AssemblyName>() { typeof(Microsoft.Extensions.Logging.LoggerFactory).Assembly.GetName() } }; var catalog = new AssemblyPluginCatalog(@"..\..\..\..\..\Assemblies\bin\JsonOld\netstandard2.0\JsonNetOld.dll", options); await catalog.Initialize(); var oldPlugin = catalog.Single(); dynamic oldPluginJsonResolver = Activator.CreateInstance(oldPlugin); var oldPluginVersion = oldPluginJsonResolver.GetVersion(); var loggerVersion = oldPluginJsonResolver.GetLoggingVersion(); Assert.Equal("3.1.2.0", loggerVersion); Assert.Equal("9.0.0.0", oldPluginVersion); }
public async Task CanConfigureDefaultOptions() { // Make sure that the referenced version of JSON.NET is loaded into memory var json = Newtonsoft.Json.JsonConvert.SerializeObject(1); PluginLoadContextOptions.Defaults.UseHostApplicationAssemblies = UseHostApplicationAssembliesEnum.Always; Action <TypeFinderCriteriaBuilder> configureFinder = configure => { configure.HasName("*JsonResolver"); }; var assemblyPluginCatalog = new AssemblyPluginCatalog(@"..\..\..\..\..\Assemblies\bin\JsonNew\netstandard2.0\JsonNetNew.dll", configureFinder); var folderPluginCatalog = new FolderPluginCatalog(@"..\..\..\..\..\Assemblies\bin\JsonOld\netstandard2.0", configureFinder); await assemblyPluginCatalog.Initialize(); await folderPluginCatalog.Initialize(); var newPlugin = assemblyPluginCatalog.Single(); var oldPlugin = folderPluginCatalog.Single(); dynamic newPluginJsonResolver = Activator.CreateInstance(newPlugin); var newPluginVersion = newPluginJsonResolver.GetVersion(); dynamic oldPluginJsonResolver = Activator.CreateInstance(oldPlugin); var oldPluginVersion = oldPluginJsonResolver.GetVersion(); Assert.Equal("12.0.0.0", newPluginVersion); Assert.Equal("12.0.0.0", oldPluginVersion); }