3

我一直无法找到这个问题的明确答案。是否保证在持久化后保留对象引用?

例如,我有一个具有一堆属性的对象,我将这个对象传递给许多不同的活动,这些活动改变了这个对象内的数据。在工作流被持久化并恢复后,是否保证所有活动都将引用同一个对象实例?

或者是否有可能通过参数或变量引用该对象的各种活动最终会得到一个副本?

4

2 回答 2

1

Because activities are sequential you are only using one activity at a time. So once an activity is complete it doesn't matter if it has a reference to the same object as a subsequent activity because the first activity has gone out of scope.

So, yes, you will get the effect of all the activities getting the same referenced object. Other than when you are using parallel activities the code execution point is inside just one activity so when you persist just one "version" of your object is persisted. When you come out of persistence that object it restored with its properties and can be passed around between subsequent activities.

I do this by making the object a variable at the top level of my Flowchart activity and handing it out to the Code Ativities inside the Flowchart

于 2013-06-20T11:44:18.037 回答
1

您实际上在这里问了两个不同的问题:

使用什么语义来调用活动?

它与普通的 .net 函数调用相同。引用类型(对象)通过引用传递,值类型(bool、int、struct、...)通过值传递(=copy)。因此,如果您继承了自己的类public class MyClass {....},它只会传递引用,并且您的所有活动都在同一个实例上工作。

哪些数据会被持久化?

完整的实例被序列化和持久化。这意味着恢复后您的所有字段都将在那里。你的类必须是可序列化的或用[DataContract]属性装饰的。另请参阅此评论: Windows Workflow Foundation 4.0 and Persistence

于 2013-06-18T07:54:50.897 回答