Accessing Arguments, Workflow Variables from custom activities

那年仲夏 提交于 2020-02-02 12:58:10

问题


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 I get them from ActivityContext?

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/2857388/accessing-arguments-workflow-variables-from-custom-activities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!