工作单元问题

发布于 2024-07-12 03:58:31 字数 352 浏览 10 评论 0原文

在以下场景中我应该如何使用工作单元模式:

我正在编写一个 winforms 应用程序。 我有一个屏幕,用户可以在其中编辑单个订单。 在此屏幕上,用户可以打开另一个表单来选择送货公司。 在进行选择之前,用户还可以在此子表单中添加/编辑现有的送货公司。

如何使用工作单元模式来实现此场景? 目前我有一个订单输入屏幕的工作单元。 我的第一个想法是将子表单也包含在这个工作单元中。 问题是,交付公司的更改应该在子表单中保留。 但是,当我保留对送货公司的更改时,这也会保留订单中的更改。

我是否应该创建第二个工作单元来对交付公司进行任何编辑? 在这种情况下,如何使该工作单元中的更改在第一个工作单元中可见?

How should I use the unit of work pattern in the following scenario:

I'm writing a winforms app.
I have one screen where the user can edit a single order.
On this screen, the user can open another form to select the delivery company. The user can also add/edit existing delivery companies in this child form before doing the selection.

How can I implement this scenario using the Unit of work pattern?
Currently I have one unit of work for the order entry screen. My first thought was to include the child form in this unit of work too. The problem is, delivery company changes should be persisted when in the child form . But when I persist changes to the delivery companies, this will also persist the changes in the order.

Should I create a second unit of work for any edits to the delivery companies? In that case, how can I make the changes in that unit of work visible in the first unit of work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

风启觞 2024-07-19 03:58:31

从您的描述来看,您似乎确实有两个工作单元。 第一个是“订单输入”,第二个是“编辑送货公司”。 每个工作单元都有某种底层类型的会话或事务。 要从子表单与订单条目进行通信,您必须将公司的对象与子表单的会话分离,然后将其重新附加到父表单。 如何实际实现这一点取决于您使用的数据访问层,但一个简单的方法是传递公司的 ID。

From your description it sounds as if you really have two units of work here. The first is "Order Entry" and the second one is "Edit Delivery Company". Each unit of work has some underlying kind of session or transaction. To communicate from the child form to the order entry you'll have to detach the company's object from the child form's session an re-attach it to the parent. How to actually implement this depends on the data access layer you're using, but an easy way is to pass around the ID of the company.

笑忘罢 2024-07-19 03:58:31

目前我有一个用于订单输入屏幕的工作单元。 问题是,交付公司的更改应该在子表单中保留。

如何使用工作单元模式实现此场景?

  1. OrderEditFormDeliveryCompanyCollectionEditForm 应共享相同的 DeliveryCompanyRepository 并共享相同的工作单元。

  2. DeliveryCompanyRepository 应从数据库返回公司 + 在工作单元期间添加的公司。

这样,新的送货公司对象应该可以在 OrderEditForm 中使用,而无需保留更改。

我是否应该创建第二个工作单元来对送货公司进行任何编辑? 在这种情况下,如何使该工作单元中的更改在第一个工作单元中可见?

并行使用的两个或多个工作单元需要特别注意数据同步。 当一个工作单元提交时,某个调解器通常会更新所有其他工作单元,正如另一个答案中已经指出的那样。

Currently I have one unit of work for the order entry screen. The problem is, delivery company changes should be persisted when in the child form.

How can I implement this scenario using the Unit of work pattern?

  1. OrderEditForm and DeliveryCompanyCollectionEditForm should share the same DeliveryCompanyRepository that shares the same unit of work.

  2. DeliveryCompanyRepository should return companies from database + companies that were added during unit of work.

This way a new delivery company object should be available in OrderEditForm without persisting changes.

Should I create a second unit of work for any edits to the delivery companies? In that case, how can I make the changes in that unit of work visible in the first unit of work?

Two or more units of work used in parallel require special attention in data synchronization. When one unit of work commits, some mediator usually updates all other units of work, as already stated in the other answer.

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