我有两个 Exports 类IScreen
,但是当我使用导入相同的类时
[ImportMany(typeof(IScreen))]
private IEnumerable<Lazy<IScreen,IJIMSMetadata>> _modules;
public IEnumerable<Lazy<IScreen, IJIMSMetadata>> Modules
{
get { return _modules; }
}
模块包含四个 IScreen 实例,但我只导出了两个。
这是容器
container = new CompositionContainer(
new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)))
);
protected override IEnumerable<Assembly> SelectAssemblies()
{
string _modulePath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Modules");
var files = Directory.GetFiles(_modulePath, "*.dll", SearchOption.AllDirectories);
List<Assembly> assemblies = new List<Assembly>();
assemblies.Add(Assembly.GetExecutingAssembly());
foreach (var file in files)
{
assemblies.Add(Assembly.LoadFrom(file));
}
return assemblies;
}