Dzm*_*voi 3 .net c# dependency-injection mef mvvm
我无法在.NET 4.5中找到System.ComponentModel.Composition.Initialization.dll(其中包含CompositionInitializer类的声明).是否已从.NET 4.5中的MEF中删除此程序集?我现在如何组成标有[导出]和[导入]属性的应用程序的部分?
假设我有这个观点:
internal partial class StartWindow : Window
{
public StartWindow()
{
InitializeComponent();
DataContext = ViewModel;
}
[Import]
public IStartWindowViewModel ViewModel { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和适当的ViewModel:
[Export]
internal class StartWindowViewModel : IStartWindowViewModel
{
public IEnumerable<Customer> Customers { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我应该在我的shell(或其他地方)添加什么来组成这些部分?
在CompositionInitializerSilverlight中与类似的类存在,但不是完整的.NET框架.MEF团队有目的地决定将他们排除在外,因为他们认为他们不合适.
逻辑是应该使用施工注入.
话虽这么说,Silverlight中使用该类的逻辑在WPF中应用完全相同.我在.NET 4中发表过关于此的博客,其中包含一个适用于完整框架的实现.
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |