将 Castle.Windsor 与 MVVMLight Toolkit 结合使用的实际示例
我确实尝试过,但找不到将 Castle IOC 与 MVVMLight 结合使用的良好工作示例。任何有关动态生成 ViewModelBase 视图模型的指导都将受到赞赏。我正在尝试使用构造函数注入将视图模型与数据源关联起来,例如:
public class MainViewModel : ViewModelBase
{
...
public MainViewModel( ISomeSortofDataRepsoitory mysomesortofdata)
myrepo = mysomesortofdata; /// data items in an observable collection
}
并且我希望 ViewModelLocator 执行以下操作:
public static void CreateMain()
{
if (_main == null)
{
...
_main = ioc.Resolve<MainViewModel>();
...
}
}
唉,没有骰子。有工作示例吗?
I have really tried but I cannot find a good working example of using the Castle IOC with MVVMLight. Any sort of guidance in the way to dynamically generate ViewModelBase viewmodels would be appreciated. I am trying to use Constructor Injection to associate the viewmodel with a data source, something like:
public class MainViewModel : ViewModelBase
{
...
public MainViewModel( ISomeSortofDataRepsoitory mysomesortofdata)
myrepo = mysomesortofdata; /// data items in an observable collection
}
and I want the ViewModelLocator
to do something like:
public static void CreateMain()
{
if (_main == null)
{
...
_main = ioc.Resolve<MainViewModel>();
...
}
}
alas, no dice. Any working examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要从 NuGet 安装 CommonServiceLocator.WindsorAdapter 包。然后在您的 ViewModelLocator ctor 中
或
完全删除 ViewModelLocator 类,并将所有 Castle Windsor 配置放入
App.xaml.cs 中
You need to install the CommonServiceLocator.WindsorAdapter package from NuGet. Then in your ViewModelLocator ctor
OR
Delete the ViewModelLocator class altogether, and put all your Castle Windsor configuration in
in App.xaml.cs