【发布时间】:2013-02-14 07:53:18
【问题描述】:
我正在尝试使用 PRISM 创建一个模块,现在我在视图中设置了 DataContext,这意味着我只能使用无参数构造函数,但这意味着我不能在我的构造函数中使用依赖注入(我使用 Unity)想要
如果可能的话,我不希望视图或虚拟机相互了解,并希望使用类似的东西
private void RegisterServices()
{
var employeeViewModel = new EmployeeViewModel();
_container.RegisterType<IEmployeeViewModel, EmployeeViewModel>();
_container.RegisterType<EmployeeView>();
EmployeeView.Datacontext = employeeViewModel;
}
我将在 EmployeeModule 中注册
这是可能的还是我应该使用后面的代码?
【问题讨论】:
标签: c# wpf dependency-injection prism unity-container