带有存储库的桌面应用程序中每个 ViewModel 的会话

发布于 2024-09-16 06:14:23 字数 794 浏览 6 评论 0原文

我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少年亿悲伤 2024-09-23 06:14:23

我建议您查看 uNhAddIns

它有一个使用 MVVM 的完整 WPF 示例。

I suggest you look into uNhAddIns.

It has a full WPF example using MVVM.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文