服务层:每个应用程序或每个视图模型 1 个实例? (或者:为每个视图模型提供自己的数据上下文)
我正在使用三层构建 C#/.Net 3.5 应用程序:UI(视图/视图模型)、服务和数据访问/持久性。
服务层: 每个服务层实例都与唯一的持久性实例相关联。服务层通过接口引用持久层。
持久层:现在,持久层接口有一个使用(Fluent)NHibernate 的具体实现。所有持久层实例共享同一个ISessionFactory。每个持久性实例都使用该工厂打开自己的 ISession。
目标:让每个视图模型在自己的数据上下文(也称为 ISession)中运行,如 Ayende Rahien。为了实现这一点,我的应用程序为每个虚拟机提供了自己的服务层实例(反过来,它也有自己的持久层实例)。对我来说,拥有这么多相同服务层类的实例有点可疑。
问题:这是一个好方法吗?放弃每个虚拟机一个服务实例并转向每个应用程序一个服务实例会更好吗?如果是这样,我该如何做到这一点并仍然为每个虚拟机提供自己的数据上下文?
谢谢你,
本
I'm building C#/.Net 3.5 app using three layers: UI (view/view models), service, and data access/persistence.
Service Layer:
Each service layer instance is associated with a unique persistence instance. The service layer references the persistence layer via an interface.
Persistence Layer: Right now, the persistence layer interface has a single concrete implementation that uses (Fluent) NHibernate. All persistence layer instances share the same ISessionFactory. Each persistence instance opens its own ISession using that factory.
Goal: For each view model to operate in its own data context (a.k.a. ISession), as suggested by Ayende Rahien. To make this happen, my app gives each VM its own service layer instance (which, in turn, has its own instance of the persistence layer). To me, having this many instances of the same service layer class smells suspicious.
Questions: Is this a good approach? Would I be better off getting away from one service instance per VM and moving to one service instance per app? If so, how would I do that and still give each VM its own data context?
Thank you,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你目前的设计是正确的。合并服务实例没有任何好处。
I think your current design is correct. There's nothing to gain by merging the service instances.