Omar AL Zabir blog on ASP.NET Ajax and .NET 3.5

Working hard to enrich millions of peoples' lives

Sponsors

News

I was
Co-Founder and CTO of Pageflakes, acquired by LiveUniverse - founded by MySpace founder.

I am
Chief Architect, SaaS Platform, British Telecom

I will be
Chief Architect, Mi...

Follow omaralzabir on Twitter

My Public Page
www.pageflakes.com/omar

View Omar AL Zabir's profile on LinkedIn

Read my blog on:

Omar AL Zabir

www.oazabir.com



Views:

Open source projects

Strongly typed workflow input and output arguments

When you run a Workflow using Workflow Foundation, you pass arguments to the workflow in a Dictionary form where the type of Dictionary is Dictionary<string, object>. This means you miss the strong typing features of .NET languages. You have to know what arguments the workflow expects by looking at the Workflow public properties. Moreover, there’s no way to make arguments required. You pass parameter, expect it to run, if it throws exception, you pass more arguments, hope it works now. Similarly, if you are running workflow synchronously using ManualWorkflowSchedulerService, you expect return arguments from the Workflow immediately, but there again, you have to rely on the Dictionary key and value pair. No strong typing there as well.

In order to solve this, so that you could pass Workflow arguments as strongly typed classes, you can establish a format that every Workflow has only two arguments named "Request” and “Response” and none other. Whatever needs to be passed to the Workflow and expected out of it, must be passed via Request and must be expected via Response properties. Now the type of these arguments can be workflow specific, it can be any class with one or more parameters. This way, you could write code like this:

Running workflow with strongly typed argument

The advantages of these strongly typed approach are:

  • Compile time validation of input parameters passed to workflow. No risk of passing unexpected object in Dictionary’s object type value.
  • Enforce required values by creating Request objects with non-default constructor.
  • Establish a fixed contract for Workflow input and output via the strongly typed Request and Response classes or interfaces.
  • Validate input arguments for the Workflow directly from the Request class, without going through the overhead of running a workflow.

If we follow this approach, we create workflows with only two DependencyProperty, one for Request and one for Response. Showing you an example from my open source project Dropthings, which uses Workflow for the entire Business Layer. Below you see the Workflow that executes when a new user visits http://dropthings.omaralzabir.com, creates a new user and setups all the pages and widgets for the user. It has only two Dependency property – Request and Response.

image

The Request parameters is of type IUserVisitWorkflowRequest. So, you can pass any class as Request argument that implements the interface.

image

Here I have used fancy inheritance to create Request object hierarchy. You don’t need to do that. Just remember, you can pass any class. You don’t even need to use interface for Request parameter. It can be a class directly. I use all these interfaces in order to facilitate Dependency Inversion.

Similarly, the Response object is also a class.

image

The Response returns quite some properties. So, it’s kinda handy to wrap them all in one property.

So, there you have it, strongly typed Workflow arguments. You can attach properties of the Request object to any activity directly form the designer:

image

There’s really no compromise to make in this approach. Everything works as before.

In order to make workflow execution simpler, I use a helper method like the following, that takes the Request and Response object and creates the Dictionary for me. This Dictionary always contains one “Request” and one “Response” entry.

image

This way, I can run Workflow in strongly typed fashion:

image

 

 

 

Here I can specify the Request, Response and Workflow type using strong typing. This way I get strongly typed return object as well as pass strongly type Request object. There’s no dictionary building, no risky string key and object type value passing.  You can ignore the ObjectContainer.Resolve() stuff, because that’s just returning me an existing reference of WorkflowRuntime.

Hope you like this approach.

Comments

필독 said:

"생,방,송" 실시간 화면으로 즐기는

"인터넷" "바,카,라"입니다.

절대 조작된 게,임에 속지마세요!

한국 방,송 확인하면서 배"팅하세요~

완벽한 보안시스템구축으로

고객의 비밀유지 최우선 완벽 보장해드립니다.

24시간 입출금이 자유로운 완벽한 솔루션!

고액출,금도 실시간으로 즉시 출금!

실.시간" 생'방,송으로 매일 천'만.원 이상 출금자 속출!!

믿을수 있는 LIVE "바,카,라"에서

대"박 한방을 터뜨리세요!

호'텔카.지'노라면 사장님도 돈을 따십니다.

입장하기▶ http://livebk05.ah.to

# January 28, 2009 3:16 PM

Wuil » The MARIFlow Work???ow Management System said:

Pingback from  Wuil  &raquo; The MARIFlow Work???ow Management System

# July 22, 2009 2:41 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)