【问题标题】:MEF Not Importing MetadataMEF 不导入元数据
【发布时间】:2011-09-22 20:01:17
【问题描述】:

所以,我用元数据属性装饰了导出,但在容器上,这些部分的元数据集合似乎是空的,因此无法正确导入带有元数据的惰性集合。

任何想法为什么会发生这种情况?

【问题讨论】:

  • 我同意这个问题没有足够的上下文来尝试回答。
  • 在 Prism 中,当我在 Shell 中定义 ImportMany 时,我必须调用容器的 ComposeParts 方法来填充集合。我希望这种行为不适用于我解决的每个实例。我希望解析的值在导入时自动组合。

标签: prism mef


【解决方案1】:

确保为 MEF 配置程序集以在引导程序内部进行探测:

protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();

            // Need to add self explicitly, otherwise MEF won't know exports we have here
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));

            // Also adding Model project - this is some project that you reference but not Module
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Model.ModelService).Assembly));
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多