c# - MEF 4.5 中缺少 CompositionInitializer。我可以用什么代替?

标签 c# .net mvvm dependency-injection mef

我在 .NET 4.5 中找不到 System.ComponentModel.Composition.Initialization.dll(其中包含 CompositionInitializer 类的声明)。此程序集是否已从 .NET 4.5 中的 MEF 中删除? 我现在如何组合标记有 [Export] 和 [Import] 属性的应用程序的各个部分?

假设我有这样的观点:

    internal partial class StartWindow : Window
    {
        public StartWindow()
        {
            InitializeComponent();
            DataContext = ViewModel;
        }

        [Import]
        public IStartWindowViewModel ViewModel { get; set; }
    }

和适当的 ViewModel:

    [Export]
    internal class StartWindowViewModel : IStartWindowViewModel
    {
        public IEnumerable<Customer> Customers { get; set; }
    }

我应该在我的 shell(或其他地方)中添加什么来组成这些部分?

最佳答案

CompositionInitializer 和类似的类存在于 Silverlight 中,但不存在于完整的 .NET Framework 中。 MEF 团队有目的地决定将它们排除在外,因为他们觉得它们不合适。

逻辑是应该改用构造注入(inject)。

话虽这么说,在 Silverlight 中应用的使用类的逻辑在 WPF 中应用完全相同。我有 blogged about this in .NET 4 ,并包含适用于整个框架的实现。

关于c# - MEF 4.5 中缺少 CompositionInitializer。我可以用什么代替?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14633470/

相关文章:

c# - 编译的 Matlab 函数只工作一次

c# - 使用 Mono 的泛型类型参数没有装箱或类型参数转换

c# - 任务排序和重新进入

c# - 最有效(阅读时间)的字符串搜索方法是什么? (C#)

c# - Rabbitmq 扇出交换 C#

.net - 从 ASP.NET 中动态生成的集合中获取选定的单选按钮

.net - 如何通过运行PowerShell脚本显示实时输出?

java - Android ViewModel 和 Paging 3 库

javascript - 如何在 KnockoutJS 中访问 ViewModel 之外的可观察对象?

wpf - 包装在面板MVVM中的用户控件