The Problem SolverWIndows Workflow Foundation
HomeShow ChangesEditPrintRecent ChangesSubscriptionsLost and FoundFind ReferencesRename

Search

History

17-10-2006 15:11:1517-10-2006 15:11:0817-10-2006 15:10:5517-10-2006 15:10:4917-10-2006 15:10:26

List all versions

Workflow Parameters
.
Summary

One thing I don’t like about Workflow Foundation is the way you need to provide parameters for a workflow. At a time where we try to as much as possibly strongly typed, so the compiler can warn us about types, we are forced to revert back to a string that must match.

Dim parameters As New Dictionary(Of String, Object)

parameters.Add("FirstName", "Maurice")

parameters.Add("LastName", "de Beijer")

workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters)

If you are going to invoke the workflow from multiple places this might become a bit of a nightmare

A slightly better solutions might be to use a helper class like this:

Dim parameters As New Workflow1Parameters

parameters.FirstName = "Maurice"

parameters.LastName = "de Beijer"

workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters.GetParameters())

Along with the following helper class:

Class Workflow1Parameters

    Public FirstName AsString
    Public LastName AsString


    PublicFunction GetParameters() As Dictionary(Of String, Object)
        Dim result As New Dictionary(Of String, Object)
        result.Add("FirstName", FirstName)
        result.Add("LastName", LastName)


        Return result
    EndFunction

EndClass

 Now this might not be a lot better but at least we have minimized the number of points the compiler cannot help us. And the benefit is that you can perform additional checks on the parameters before starting.

In case you where wondering why you can't just set the properties directly like so:

workflowInstance = workflowRuntime.CreateWorkflow(GetType(Workflow1), parameters.GetParameters())

workflowInstance.FirstName = "Maurice"

workflowInstance.LastName = "de Beijer"

workflowInstance.Start()

The workflowInstance variable doesn’t point to an object of the workflow type itself but to a wrapper containing the workflow definition. So it simply doesn’t have the properties you defined in the workflow.

Wiki Usage

This wiki site is supposed to be a shared resource. As a shared resource everyone is encouraged to add new content or modify existing content!

Enjoy the WF wiki.

Recent Topics