I have a workflow composed of many custom activities. All these activities need to access startup arguments of the workflow itself. I can define InArgument inside all these custom activities and bind the workflow arguments to custom activity arguments but I am not comfortable with this solution. What is the best way to access workflow level argument and variable declarations from custom activities. Can开发者_StackOverflow中文版 I get them from ActivityContext?
Thanks.
One way we've looked at this with our custom activities is using the Properties property available in the ActivityContext. We have an activity with an InArgument which adds an ExecutionProperty in the execute method, so you end up with:
public InArgument<Custom> MyObject {get;set;}
...
context.Properties.Add("Contact",MyObject.Get(context));
Then in your other activities you can check to see if this has been set
context.Properties.Find("Contact")
Obviously if you're doing this a lot I'd recommend using a constant somewhere rather than magic strings, but it should save you having to add the same argument over and over when designing.
精彩评论