Search code examples
workflow-foundationworkflow-foundation-4

Sharing variables between WorkFlow Application / SIngelton Workflow


i am running a c# application that is launching workflow activities for some purposes (using invokeworkflowapplication). I would like to be able to share a static class between all flows i am launching from my application (some sort of singelton class that they can all acccess at any time).

Is there such a method to make the flow i am launching run in some singelton context??

Thanks!


Solution

  • A nice way to share data between different workflows and instances is to make a workflowInstanceExtension. This extension must be added by your application and its same instance be used to all your WorkflowApplications, invoker or service, so it will be a "singleton".

    Example:

    MyDataSharingExtension dse = new MyDataSharingExtension();
    
    WorkflowApplication wfApp1 = new WorkflowApplication();
    wfApp1.Extensions.Add(dse);
    
    WorkflowApplication wfApp2 = new WorkflowApplication();
    wfApp2.Extensions.Add(dse);
    

    Then, inside an activity, you can call

    context.GetExtension<MyDataSharingExtension>().GetData();
    

    If you need the data at workflow level(not code), you could make a custom activity to retrieve the data to a variable.

    If it don't fit your needs, take a look at this implementation of enterprise variables