开发者

How do I pass objects to descendant activities in WF4?

开发者 https://www.devze.com 2023-04-09 16:00 出处:网络
I\'m new to Workflow Foundation 4, and I\'ve been struggling for days to do something that seems like it should be completely trivial. Note that I\'m mostly coding C# activities here, not really all t

I'm new to Workflow Foundation 4, and I've been struggling for days to do something that seems like it should be completely trivial. Note that I'm mostly coding C# activities here, not really all that experienced with XAML.

To summarize my question, I am trying to figure out how to programmatically pass a session object (or just any object!) to all descendant child activities (or at least to the activities that have been taught to make use of the session).

I already have an "outer" activity, on which you can drop any other activity (including composites like Sequence, Flowchart, and anything else). So, it only has one direct child activity, but that in turn may have several generations of descendants (the contents of which may vary), which is important to keep in mind here. I don't know ahead of time how many descendant activities there will be, or what their types are.

The "outer" activity, before it schedules its child activity, establishes some kind of session object (let's assume just an object named "Session"). Here's the main problem: I have certain specialized custom inner activities that need to know how to grab this Session reference (i.e., other activities won't know about Session, or don't need to). These custom inner activities might be several generations descended from the"outer" activity, so I can't just have the outer activity inject the Session to its single child or something like that.

Apart from using some very costly-messy-and-error-prone recursive reflection, I can't find any way to accomplish this. I've tried using workflow Variables, InArguments and OutArguments, but have had no luck getting them to continue down the generations. I'm thinking Variables are the way to go but I've had tro开发者_如何学Cuble figuring out the correct way to do this (I apologize for my newbiness). At this point I'm not even sure if I should approach this by passing the object down or having the descendents search back up.

What's the best way to accomplish this?


There are two options.

  1. Use an extension - child activities that are aware of the extension can get it and read data from it.
  2. Use a Scope Activity that sets an Execution Property - see Execution Properties Sample
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号