带有存储库的桌面应用程序中每个 ViewModel 的会话
我一直在使用 NHibernate、WPF、Prism 和 Unity Container 编写 WPF DESKTOP 应用程序,但在服务/存储库中的会话管理以及如何使用 Unity 通过依赖项注入干净地完成它方面遇到问题。
阅读使用 NHibernate 构建桌面待办事项应用程序后,我现在有一个会话每个 ViewModel / Presenter。
但是,如果我的视图模型上有多个服务,我必须将会话传递到每个服务中,这看起来很麻烦,而且不太正确,因为我想通过存储库执行所有数据访问。
例如,
CustomerMaintenanceViewModel
{
service1.Session = SessionForThisPresenter;
service2.Session = SessionForThisPresenter;
service3.Session = SessionForThisPresenter;
service1.GetAllSomething();
service2.GetAllSomething();
service3.GetAllSomething();
}
每个服务本质上都是存储库上的一个外观,我希望该演示者的每个存储库都参与同一个会话,而无需显式设置它。
任何有关如何处理此问题的建议将不胜感激,因为我确信有一个非常接近的解决方案,但我不确定如何去做。
I have been writing a WPF DESKTOP application using NHibernate, WPF, Prism and Unity Container but have a problem in terms of Session Management in Services / Repositories and how to do it cleanly through dependency injection using Unity.
Having read Building A Desktop To Do-Application With NHibernate I now have a Session Per ViewModel / Presenter.
However, if I have several services on my viewmodel I have to pass the Session into each and every service which seems cumbersome and not quite right as I want to perform all data access through a repository.
e.g
CustomerMaintenanceViewModel
{
service1.Session = SessionForThisPresenter;
service2.Session = SessionForThisPresenter;
service3.Session = SessionForThisPresenter;
service1.GetAllSomething();
service2.GetAllSomething();
service3.GetAllSomething();
}
Each service is essentially a facade over a repository and I would want each repository for this presenter to be involved in the same session without explicitly setting it.
Any advice on how to handle this would be most appreciated as I am sure there is a solution quite close but I am not sure how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您查看 uNhAddIns。
它有一个使用 MVVM 的完整 WPF 示例。
I suggest you look into uNhAddIns.
It has a full WPF example using MVVM.