Search code examples
c#workflow-foundation-4

Using POCO Types in a workflow


I am working with WF4 and need to use Types I created before, in a Workflow, but I'm not sure of my strategy.

I have a class:

class MyClass
{
    public MyClass()
    {
        //Constructor Logic
    }

    public void Connect()
    {
        //Connect to a TCP/Device for example
    }

    public void Disconnect()
    {
        //Disconnect from a TCP/Device for example
    }
}

and i want to use it in a WF4 Flowchart or StateMachine.

Then i have my main application:

class Program
{
    private MyClass myObject;
    WorkflowApplication WorkflowApplicationHoster;
    static void Main(string[] args)
    {
       myObject = new MyClass;
       IDictionary<string,object> input = new Dictionary<string,object>() {{"MyClassInstance",myObject} };
       WorkflowApplicationHoster = new WorkflowApplication(new MyWorkflow,input);
        WorkflowApplicationHoster.Run();
    }
}

In my Workflow i have the "InArgument" -> "MyClassInstance" which is a MyClass Type and i use it for the whole workflow.

This doesn't feel correct. How to use own classe with the WF4?


Solution

  • OK -- so if I'm understanding this properly what you're trying to understand is how to get a new instance of your type into the workflow so it can be used. Generally speaking I've always been able to simply declare a variable and initialize it in some manner, but the question becomes what kind of initialization do you need?

    If you just need to create a new instance of it, like shown above, then declare a variable of your type and in the Default Value issue the New {TypeName}() to create a new instance.

    However, you're going to need to provide a lot more information if this doesn't help.