Skip to main content

Windows Workflow: Re-introducing old anti-patterns?

As part of my day job I've been experimenting with Windows Workflow in both modifying the existing TFS2010 build templates and as a way of controlling the process flow in our new suite of applications. On the most part I've been really impressed; when you sit in a process workshop watching the business users mapping the existing steps out on a white board (or even a wall) it is quickly apparent that showing them a similar flow should hold significant benefits. Gherkin goes some way towards creating a syntax/language that works for both technical and non-technical people, but it is a test language verifying the application is working as intended - you don't write the process itself in gherkin. We've also found (from experience) that gherkin has a reasonable learning curve for both technical and non-technical users; whilst most people seem to find it easy to relate to the visual element of workflow with little or no training.

But as I opened I've been impressed for the most part with what I've seen of workflow so far. Over the past 10 years or so there has been a significant push to improve the quality of code that is produced. We have unit tests and TDD, guidelines such as SOLID and DRY all designed to aid the developer in creating code that should be easier to maintain and less bug-ridden. This has all helped and it's not often that you should come across methods inside of a class that remind you of the days of classic ASP and/or VB6 with massive blocks of procedural code containing large conditional sections of code; harbouring numerous responsibilities, reasons to change and worse still, code that can't be tested in isolation(*).

Getting back to workflow re-introducing old anti-patterns, step forward the default build template for TFS2010. I'm not sure how many people have taken a look at this workflow, or worse still had to work with / modify it? That nice happy feeling of replicating what the business wants quickly vanishes and it's like taking a step back in to code from the early 90's. Everything (and I mean everything) is in one single workflow. In the designer, even at 50% scale, you have to scroll down several pages to move through one conditional block of code. Want to find where a particular exception is thrown, it's probably quicker to open up the workflow as plain XAML and text search for the exception type and/or message text. Even if you figured out how to host the workflow to test it, if you want to test the "gated check-in" functionality you'll have to run the entire workflow from start to finish just to reach the code under test. Want to isolate a hard to test entry point into the gated check-in workflow; you'll have to figure out the exact scenario to replicate it because you can't set it up or Moq the areas you're not interested in. Sound familiar, I'm sure everyone's worked on a code base that suffered the same problems but in real code we're mostly past those problems now.

It doesn't have to be this way, workflow allows sequences and flows to be declared in separate XAML files and nested inside a larger workflow. There's absolutely no reason why the gated check-in sequence could not have been it's own XAML file; with it's own in/out arguments. It quickly becomes SOLID and DRY - it only needs to change when the requirements or process for gated check-in changes and can easily be tested in isolation. I might not be able to figure out how to host / run the entire build template, but even now I'd probably be able to throw together a workflow host application that loaded, set-up and ran a "gated check-in" XAML file.

So workflow doesn't have to re-introduce old anti-patterns but all the time we have real-world examples that contain bad practises it will be harder for less experienced developers not to replicate. It's probably worth remembering that there are many developers that have come into the workplace never having to suffer the pain of procedural code that generated many of the recognised anti-patterns. It would be a big step back for development (and workflow) if examples like TFS became common place! As a side project I'm trying to gain a full understanding of the default build template (something that also seems to be missing from the on-line Microsoft TFS documentation) and break the XAML into smaller, focused sequences / flows that are easier to understand. Workflow does look like it can successfully be the procedural glue that handles the transition between state and complex / long running process flows; but it does need to adhere to the same testing and principles as the code it contains!

(*) This sort of code might still exist but I'm happy to say that I've been lucky to work in and with teams that don't produce it.


Popular posts from this blog

Problem installing AWS CLI

It never feels like a good start when you're trying to start out with something and the install fails with an obscure error! I was just trying to install the Amazon CLI following the instructions at and ran into the following error when running 'pip install awscli': Collecting awscli Could not find a version that satisfies the requirement awscli (from versions: ) No matching distribution found for awscli I appeared to have a correct version of Python installed (v2.7) and checking "PIP -v" indicated that 9.0.1 was installed. That all seemed to tick the required boxes but digging around a little more I did see that some people had had issues with various versions of PIP so I found / ran the following to upgrade to the latest vesion: curl -o python This installed v9.0.3 of PIP which burst into life when I re-ran 'pip install awscli' and everything seems to be ok. Like…

Mocking HttpCookieCollection in HttpRequestBase

When unit testing ASP.NET MVC2 projects the issue of injecting HttpContext is quickly encountered.  There seem to be many different ways / recommendations for mocking HttpContextBase to improve the testability of controllers and their actions.  My investigations into that will probably be a separate blog post in the near future but for now I want to cover something that had me stuck for longer than it probably should have.  That is how to mock non abstract/interfaced classes within HttpRequestBase and HttpResponseBase – namely the HttpCookieCollection class.   The code sample below illustrates how it can be used within a mocked instance of HttpRequestBase.  Cookies can be added / modified within the unit test code prior to being passed into the code being tested.   After it’s been called, using a combination of MOQ’s Verify and NUnit’s Assert it is possible to check how many times the collection is accessed (but you have to include the set up calls) and that the relevant cookies have …

Injecting HttpContextBase into an MVC Controller

It is a shame that when the ASP.NET MVC framework was released they did not think to build IoC support into the infrastructure. All the major components of the MVC engine appear to magically inherit instances of HttpContext and it’s related objects – which can cause no end of problems if you are trying to utilise Unit Testing and IoC. Reading around various articles on the subject just to get around this one problem requires the implementation of several different concepts and you are still left with a work around. The code below, along with the other links referenced in this article is my stab at resolving the issue. There’s probably nothing new here, but it does attempt to relate all the information needed to do this for Castle Windsor. The overview is that all controllers will need to inherit from a base controller, which takes an instance of HttpContext into it’s constructor. It then overrides the property HttpContext in the main controller class, supplying it’s own version…