1

Exports という 2 つのクラスがありますIScreenが、同じものをインポートすると

[ImportMany(typeof(IScreen))]
private IEnumerable<Lazy<IScreen,IJIMSMetadata>> _modules;
public IEnumerable<Lazy<IScreen, IJIMSMetadata>> Modules
{
        get { return _modules; }
}

モジュールには IScreen の 4 つのインスタンスが含まれていますが、エクスポートしたのは 2 つだけです。

これはコンテナです

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;
}
4

1 に答える 1

2

AggregateCatalog を使用しているため、実行中のアセンブリを含む場所に AssemblyCatalog と DirectoryCatalog の両方を追加していないことを確認してください。

たとえば、次のコードは、同じアセンブリを 2 回処理することを回避します。

var catalog = new AggregateCatalog();
var locations = new List<string>();
foreach (var loc in GetPluginDirectories())
    if (!locations.Contains(loc))
    {
        catalog.Catalogs.Add(new DirectoryCatalog(loc));
        locations.Add(loc);
    }

var asm = Assembly.GetExecutingAssembly();
if (!locations.Contains(Path.GetDirectoryName(asm.Location)))
    catalog.Catalogs.Add(new AssemblyCatalog(asm));
于 2013-10-14T20:29:22.343 に答える