Reputation: 313
I am converting code from dotnetframework to a dotnet6 WPF Hybrid app, and use MEF. The compose show the plugin and metdata in the container but neither collection via [ImportMany] have any contents. I get no exceptions. The plugins do load in a DotnetFramework app. has anyone any ideas on getting ImportMany to work?
public class PluginHandler
[ImportMany(typeof(IKapprisWebViewerClientPlugin))]
private static IEnumerable<Lazy<IKapprisWebViewerClientPlugin, IKapprisWebViewerClientPluginData>>? plugins { get; set; } = new
List<Lazy<IKapprisWebViewerClientPlugin, IKapprisWebViewerClientPluginData>>();
[ImportMany(typeof(IKapprisWebViewerClientPlugin))]
private static IEnumerable<IKapprisWebViewerClientPlugin>? plugins1 { get; set; } = new List<IKapprisWebViewerClientPlugin>();
public PluginHandler()
{
//An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string directory = new Uri(Path.GetDirectoryName(exePath)).LocalPath;
//Adds all the parts found in all assemblies in
//the same directory as the executing program
catalog.Catalogs.Add(
new DirectoryCatalog(
directory, "kwc*.dll"));
//Create the CompositionContainer with the parts in the catalog
CompositionContainer container = new CompositionContainer(catalog);
//Fill the imports of this object
container.ComposeParts(this);
//container.SatisfyImportsOnce(this);
}
}
the plugin class
[Export(typeof(IKapprisWebViewerClientPlugin))]
[ExportMetadata("Name", "IManage 10 / Cloud")]
public class WebViewerIntegration : WebViewerClientPlugin
{
...
}
public interface IKapprisWebViewerClientPluginData
{
/// <summary>
/// Name used to identify plugin
/// </summary>
string Name { get; }
}
Upvotes: 0
Views: 367