Wednesday, September 19, 2012

Hosting a Dependency Injected WCF Service

I was having a discussion with a colleague today about how I use my blog as my digital memory or to save keystrokes when helping others. A few moments later, we were debugging a problem that I was convinced I had solved before. Strangely, I have no blog post for this.

So here it is.

Let’s say you’ve got an application and you’d like to expose a part of it on the network. Maybe you want to allow your mobile phone to control your app, or maybe you want two applications to talk to another. There are lots of possibilities here. Within the Microsoft space, one of the best ways to do this is through WCF. From an implementation perspective, it’s all about the ServiceHost.

Let's say the service looks something like this:

using System.ServiceModel;

namespace Example
    public class Service : IService
        public string SayHelloTo(string person)
            return String.Format("Hello {0}", person);

    public interface IService
        string SayHelloTo(string person);

And the code to host the service looks something like this:

using System.ServiceModel;

public Example

    public class ServiceTests
        public void WhenServiceIsHosted_UsingTypeNameAndConfigIsPresent_ShouldConfigureTheServiceWithValuesInTheAppConfig()
            var host = new ServiceHost(typeof(Example.Service));
                "The service host was not configured.");
            // optionally, if you had to launch it
            // host.Open();
            // Console.ReadLine();
            // host.Close();



This all good for basic services. But what if your service is assembled using constructor injection? You won't be able to simply pass the Type to the ServiceHost constructor.

public void WhenServiceIsHosted_UsingInstanceAndConfigIsPresent_ShouldConfigureTheServiceWithValuesInTheAppConfig()
    Service serviceInstance = ConstructService(); // omitted for clarity
    var host = new ServiceHost(serviceInstance);


Only, this test fails! It seems that by passing an instance of our service to the ServiceHost the values in our app.config are not being read.

To correct this issue, the service is configured as singleton and requires us to decorate our concrete implementation of that service with a ServiceBehavior attribute, and configure the InstanceContext for our instance as a Singleton.

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class Service : IService
    // ....

Bam! Passing tests.

Tuesday, September 18, 2012

Marking Kanban Items as Blocked

Sometimes items in your Kanban workflow reach a state where they cannot proceed. Maybe they’re have a dependency on another item; maybe there’s an issue or pending decision. When this happens, you want to increase the visibility of these issues by marking them as blocked.

Fortunately, the SEP Teamworks tool which I mentioned in my last post, supports such a feature. Simply right-click (or on a touch device, tap-and-hold) and use the context-menu to mark it as blocked.


Simple, right? Well, the first time I tried this feature, the tool crashed. Turns out that you must have a Blocked field in your work item definition.

Adding this field to your work item definition is easy.

  1. Retrieve the work item definition from your TFS server using the witadmin exportwitd command:

    witadmin exportwitd /collection:<server-name> /p:<project-name> /n:Task /f:Task.xml
  2. Insert a new field definition into the FIELDS node. Note that the namespace doesn’t matter. As TFS doesn’t contain a definition for Boolean fields, you must set it up as a string with Yes/No values.

    <witd:WITD application="Work item type editor" version="1.0" xmlns:witd="">
      <WORKITEMTYPE name="Task">
        <!-- edited for clarity -->
          <FIELD name="Blocked" refname="Custom.Blocked" type="String">
            <ALLOWEDVALUES expanditems="true">
                <LISTITEM value="Yes" />
                <LISTITEM value="No" />
               <DEFAULT from="value" value="No" />
  3. (Optional, but highly recommended) If you want to change the Blocked field outside of the SEP Teamworks tool (such as inside TFS), you’ll need to describe the field inside the FORM node. The syntax is relatively straightforward:

    <witd:WITD application="Work item type editor" version="1.0" xmlns:witd="">
      <WORKITEMTYPE name="Task">
        <!--edited for clarity -->
           <Control Type="FieldControl" FieldName="Custom.Blocked" Label="Blocked:" />
  4. Lastly, push your changed work item definition back to the server using the witadmin tool:

    witadmin importwitd /collection:<server-name> /p:<project-name> /f:task.xml

With these changes in place, the SEP Teamworks tool puts a visual over blocked items.


My next post will look at some other handy customizations to the TFS work flow.

Tuesday, September 11, 2012

Configuring SEP Kanban board

In my last post, I showed how I’ve modified the State field of my TFS Work Item definitions to resemble my Kanban workflow.  This post we’ll take a look at how I’ve configure my digital board and highlight the pros and cons of my current approach. Maybe you’ll find this useful, maybe you’ve got some recommendations – either way, I’d love to hear from you.

Setting things up

  1. Download and install the SEP Digital Kanban board:
  2. Run the MSI. Defaults all the way through.
  3. Run the app. You’ll need to configure the board with a few settings.
  4. Pick a server:


  5. Select your TFS Server:

  6. Select your TFS project and select a Query that returns all your work items. I have a small query to return only Tasks and Bugs: 

  7. In order to get the workflow correct, you’ll need to manually order the States of the Work Item. Change the Work Item States –> Order.



    The Item states should be in this order:

    • Proposed
    • Active
    • Selected
    • In Development
    • Ready for Test
    • Testing
    • Acceptance
    • Closed

  8. Depending on your Project collection, you may have additional work item definitions with their own states. You may have to turn off any states that aren’t included in our work item states. (This screen shot shows Resolved, Design and Ready states have been turned off)

  9. Set up some limits.


Cool Features

Touch enabled: While the main feature that I was interested in was representing my tasks in TFS, what sold me on this tool was the fact that it was designed for touch. My HP TouchSmart now operates as our digital kanban board.

Swim lanes: Another great feature is the ability to view the features in their own collapsible Swim Lane. There are many great uses for swim lanes such as grouping by Area, Iteration, Priority, Assigned to, Triaged, etc. Most scalar value fields can be used. What’s also great about this feature is that you can simply drag a work item into a swim lane to assign that field value. This makes it easy to keep your work items organized.

Create or Edit Work Items: The tool takes advantage of the form layouts defined in the work item definition, so you can get the same TFS Team Explorer editor experience right on your Kanban board. Large buttons at the top of the user-interface make it simple to add new bugs or tasks as they arrive, and I can open an item from a context-menu to get or edit details about the task at hand.

Caveats and Annoyances

Tasks and Bugs: Unfortunately, I’m only tracking Task and Bug work items because these are the items that I’ve customized. I would like to Use Stories where I describe the work as a high level story and then realize that effort in tasks. At the moment, I’m using TFS 2008 which doesn’t support hierarchal tasks, so I’m kind of stuck on that.  If I could track hierarchal tasks, I’m not entirely sure how I would use this tool – where should the Stories appear on the board if only some of the development tasks are complete?

No sub-columns: One of the features that this tool lacks is that ability to create sub-columns. Ideally I would like to treat Development as one column with two sub-columns (“In Development” and “Ready for Test”) and put a WIP limit on Development. Having this capability highlights testing bottlenecks and would ensure that the development team is invested in seeing their completed efforts are delivering into the client’s hands.

No central configuration: While I’m sure that the target usage for this application is to use it on a touch-device as a whiteboard replacement, the tool doesn’t offer any means to save the configuration externally or toggle between configurations. This is a minor annoyance because most of my team members are jumping on board with this tool to provide their status updates. Also, as I have multiple projects, a means to jump between configurations would be ideal.

All in all, it’s a great resource.

My next post will talk more about customizations to the Work Item definitions that support my workflow.

Friday, September 07, 2012

Using Kanban with TFS

I’ve been actively campaigning for Kanban within our organization. This means giving lunch info-sessions, lending my ear to projects that need a boost, speaking with management and project managers. What I find so fascinating is that people get charged by such a simple concept. It can’t be this easy – but it is – and it’s applicable to most projects. Really? Really.

I’m thrilled to see people “get it”, because it’s easy to draw parallels between work as a pipeline and continuous delivery. Concepts like “push-to-deploy”, continuous integration and regression testing graft directly to parts of your workflow. And while the core concepts of continuous delivery aren’t prerequisites to Kanban, they are certainly mutually beneficial. By leading with Kanban, it’s easier to see value proposition of continuous delivery.

A common theme from all my discussions is I strongly recommend teams “resist the urge to replace a whiteboard with software”. Software can be a trap if applied too early to the process. Pick the wrong tool and you’ll spend your time worrying about tooling rather than the issues that are preventing you from delivering value. Nothing beats the immediate, tactile capabilities of a post-it note moving from one column to another. Focus on the workflow, foster adoption within the team, optimize and then find software to fit your needs. It should rarely be the other way around.

Unless of course, your team is remote.

I’ve heard of some innovative ways to get around this limitation, including a webcam pointed at your Kanban board. This seems like too far a stretch for me, and it’s time for my project to move our spreadsheets and post-it notes into a more centralized digital format.

While there are many cloud-based solutions, a critical feature for me is to own the data. And integrate directly with Visual Studio. (Okay, two key features). Team Foundation Server does Work Items. Let’s start there.

Customizing Work Item Definitions

Out of the box, the definition for Task has all the fields we need to implement our Kanban workflow. The main customization that we need to make is to the State field: we’ll model the various stages of our workflow using this field.

Our current workflow looks something like this:

  • Proposed: This is our backlog
  • Active: Items that will be included in this release.
  • Selected: These are items that we will develop next.
  • In Development: Items being actively worked on.
  • Ready for Test: Development is complete and is pending deployment or verification.
  • Testing: Items that are being validated by testers.
  • Acceptance: Items at are ready for client review.
  • Closed: Completed items.

We’ll need to model these various states in our work item definition, which we can retrieve from TFS using the following command line:

witadmin exportwitd /collection:https://<tfs-server-name> /p:<project-name> /n:Task /f:task.xml

Our State field is represented in the work item definition as:

<witd:WITD application="Work item type editor"

  <WORKITEMTYPE name="Task">

    <FIELDS> <!—- simplified for clarity -->

      <FIELD name="State" refname="System.State" type="String" reportable="dimension">
        <HELPTEXT>The workflow state of the task</HELPTEXT>


    <WORKFLOW> <!-- simplified for clarify -->

        <STATE value="Proposed" />
        <STATE value="Active"/>
        <STATE value="Selected" />
        <STATE value="In Development" />
        <STATE value="Ready for Test" />
        <STATE value="Testing" />
        <STATE value="Acceptance" />
        <STATE value="Closed" />



Transitioning between States

One of the powerful features of customizing the work item definition is the ability to define rules that govern how the item transitions between states.  There is a bit overhead to define these transitions and it can become cumbersome if you have a lot of states, but overall this is a good exercise to formalize what each column means and why something would move from one state to another.

State transitions are fairly easy but there are a few small caveats:

  • You must provide a default state (transitioning “” to “Proposed”)
  • Each transition must have a default reason, plus any number of additional reasons.
  • Any transition that is clearly not defined is not supported.

There are a lot of neat features that you can define here, some of which will have to wait for another post, but here’s a quick excerpt that demonstrates state transitions:

<witd:WITD application="Work item type editor" 
    <!-- edited for clarity -->

        <!-- snip -->
            <TRANSITION from="" to="Proposed">
                <DEFAULTREASON value="New" />
            <TRANSITION from="Proposed" to="Active">
                <DEFAULTREASON value="Scheduled in Release" />
            <!-- not shown:
                proposed -> development
                proposed -> closed

                active -> selected
                active -> development
                active -> proposed
                active -> closed
                selected -> development
                selected -> active

                development -> ready for test
                development -> selected
                development -> active

                ready for test -> testing
                ready for test -> development

                testing -> acceptance
                testing -> ready for test
                testing -> development
                testing -> selected
                testing -> active

                acceptance -> closed
                acceptance -> active

                closed -> active


With our customizations in place, we can push our work item definition back to TFS:

witadmin importwitd /collection:<server-name> /p:<project> /f:task.xml

Now when we open a Task definition, we see that the State transition drop-down is constrained by the transitions we’ve defined and the Reason column is prepopulated with our reasons.


Visualizing TFS Work Items in a Kanban tool

TFS has a rich API and many integrations available (especially with Office stack) but I certainly wouldn’t have gone through all of this trouble if there wasn’t a replacement for my whiteboard and post-it notes.

I recently found this free tool, provided by SEP, that does most of things I want. Because the application supports touch, I’m able to put my HP TouchSmart to good use.


My next post will talk more about setting up the SEP teamworks tool.

Tuesday, September 04, 2012

A week with Windows Phone 7

I realize I’m probably a bit late to the party on this blog post as Windows Phone 8 is around the corner, but worth writing about anyway.

I've been an iOS boy for a long time, starting with my trusty 3G in 2008 and my iPhone 4 in late 2010. But when my iPhone 4 was stolen, my options here in Canada were pretty limited. I could either replace my iPhone 4 for over $600, or count the months remaining on my 3 year contract until I could afford an upgrade, where each month was a $20 savings from the $600. Disappointed and rejected, I reluctantly plopped a new SIM into my old iPhone 3G and over the course of a few months I began to realize the crushing effect of Apple's development philosophy: "Long live new hardware! Old hardware be damned."

I got tired waiting, and on a whim I scanned kajiji for used phones. I stumbled upon a lightly used Nokia Lumina 710 for a little over $100 – a bargain compared to my iOS options. As a windows developer who knows a thing or two about WPF and XAML, I couldn't resist.

First impressions

Although I want to focus on the Windows Phone operating system, I need to remark on the device a bit. As a phone, the Nokia performs well, fits comfortably in your hand, has a bright screen and a decent 5 megapixel camera. This device features a dedicated button for the camera which can bring the device out of stand-by so that you can use it as a camera, a feature all phone should have if they don't already.

It seems like a funny feature to showcase, but I'm quite impressed by the speakerphone, which takes up sizeable area of the lower back of the phone. I’ve found this feature to be lacking in both my iPhone and iPad, but now I can actually use the speakerphone to have conversations with people in the room, or hear the dialog in a YouTube video.

My only complaint is that the hardware buttons at the bottom of the device can't be used to bring the device out of stand-by – that feature is exclusively owned by the power button on the top. I don't know if this behavior is something specific to this Nokia device, but I find myself pressing these buttons constantly – an old habit that this iOS'er is certainly having a hard-time breaking.

User Interface

So far, I'm really quite impressed with my Windows Phone. From a look-and-feel perspective, the interface is a slick metro theme. Scrolling is smooth and transitions between screens are animated. Most importantly, applications start quickly and are responsive.

Hardware Buttons

Windows phones have three hardware buttons: "back", "windows", "search". The windows button can be pressed at any time and returns you to the Start screen where you can launch applications. More on the search button later.

If you’re used to iOS where navigating through an application is done through software-based buttons, the “back” button seems like an oddity the first time you use it.  Most applications in Windows Phone rely on the back button to provide backward navigation, similar to the behaviour of the back button in a web browser. However, if the application has reached its initial starting point, the back button will close the application and return you to the start screen.  If you have multiple applications open, the back button will close the current application and return you to the previously running application – this seems peculiar at first.  Alternatively, you can press-and-hold the back button which will allow you to switch between applications, much like switching tabs in your browser.

It's funny that after relying on software-based buttons in iOS for so long, I was reluctant to switch to hardware-based buttons for aesthetic reasons and it took a while to get used to. Once you've acclimatized to having these buttons, you realize that most applications take advantage of this concept so their user-interfaces aren't cluttered with software buttons. The Windows Phone operating system builds upon this by providing a consistent place in applications for software buttons, called the app bar, located at the bottom of the screen just above the hardware buttons. These two concepts work really well together and they quickly become second nature.

After a few days, I found myself wanting to tap the left-side of my iPhone whenever I picked it up.


On the iPhone, you can tell a lot about someone’s personality not only by the way they've customized the outside of the device but by the way they've arranged their applications: what's on their home screen? what's in the dock? With Windows Phone, i can drag tiles around to personalize my start screen, though it doesn't have the same feeling as folders and multiple screens on iOS. I'm not saying this is bad, it's just different. It’s stripped down simple. So simple, it works brilliantly.

Apart from the start screen, I can swipe to the right to bring up a full list of applications, which are sorted alphabetically. It's easy to find an application if you know its name, but grouping them by category or folder like Windows 8 would be a huge step up. It took iOS a few releases to introduce folders, maybe a future release will support this.

The phone also supports a simple theming concept which is comprised of a background and accent colour. The theme is based on the concept that darker colours use less power for the OLED screen. The accent colour is picked up by most applications and changes the colours used by the main home screen.

You can also customize the images on the lock screen and customize ringtones and other sounds. (I am so freaking bored with iPhone’s notifications and reminders.)

Live Tiles / Start Screen

In Windows Phone, the tiles are "live", meaning that each application can provide additional information to the Start screen. Whereas iOS applications are limited to small numeric overlays overtop of their applications (a handful of Apple applications like Weather and Calendar update their icons to reflect current conditions and date), Windows Phone allows applications to fully customize the front and back of their tiles.

As you would expect, the Weather application shows an icon for the current weather conditions with the current temperature and the Calendar application shows the time and details of your next appointment. Some of the apps provide a much more interesting display, like the Contacts app creates an animated mosaic of my friends cover photos, or the Photos app which rotates through some of my favourites.

Where the Live Tiles feature rocks is that some applications let you pin individual elements of the application to the Start screen. Most notably, I pinned my wife’s contact card to the start screen which shows me her photo and recent activity. Other apps, like FourSquare let you pin things like locations. It’s a mix between developer flexibility and user customization.

In the end, the Home Screen becomes more than just a launching point for your favourite applications – it’s a personal dashboard that provides meaningful information at a glance. This is extremely powerful.

The Social Connection

Windows Phone is touted as being great as a "social" phone, and it's easy to see how that connection is made. When you first turn the device on, my first inclination is to setup my address book. I started with my Google account because this holds my contacts, email and a few personal calendars. Easy.

But Windows Phone also natively supports Facebook. Following the same process to hook up my Google account, I plugged in my Facebook credentials and something magical happened: the phone merged my overlapping contacts between online providers (Facebook, Google, Windows Live, Twitter, LinkedIn) into a single holistic view. Not just their contact details, but their status updates and online photos are instantly available from their contact card. This alone is pretty awesome but it goes one further – all contact touch-points from the phone are also seen in the history for the contact: emails, phone calls, text messages are all in one place.

The social network integration in the phone runs deep. All of my Facebook photo albums are immediately available from the phone’s photo gallery. I can post to twitter, Facebook and LinkedIn simultaneously. The built in Camera application lets you post pictures and videos to Facebook with a single click. I’ve been more active on Facebook this month without ever launching Facebook. Cool.

Other Perks

There are many other neat features in Windows Phone 7, but here’s a few notables:

  • Predictive Text: While iOS doesn’t provide auto-correct suggestions until you’ve misspelled or typed most of a lengthy word, WP7 provides a list of possible words above the keyboard as you type. The list is scrollable left/right and often provides suggestions that are exactly what you need, or darn close.
  • Search: One of the hardware buttons is for “search” which at first glance is just a shortcut for Bing. However, at the bottom of the search interface are three software buttons: one provides a handy feature to search by speaking to the device, the second leverages a built-in QR-Code (and MS-Tag) scanner, the third is a music search that can identify the currently playing song.
  • Speech: A slightly hidden feature, if you hold the windows key down for a second, a dialog will prompt you for voice commands. It’s not quite Siri, but you can text a message to someone without looking at the screen.
  • Office: Windows Phone 7 ships with a mobile version of Office, complete with OneNote.
  • Copy/Paste: While iOS didn’t have this until several releases in, the copy/paste feature within Windows Phone is pretty intuitive. And, it’s part of the initial release (jab, jab).


Much like iOS users pined for Copy-Paste, Windows Phone has a few short comings.

  • Screen Capture. Surprisingly, Windows Phone does not let you take pictures of the current screen. This is a bit baffling, but apparently coming in the next release. There’s a way to get screen-captures of the device but it requires the device to be registered with a paid-developer account. (That sucks. I will post screen-shots once I get my accounts sorted out)
  • App Store. This is by far the biggest challenge for the platform as the lack of applications makes it clear that this is the forgotten player in this space. Although I hope to write a few applications, the platform currently lacks the critical day-to-day apps like online-Banking. These apps are desperately needed, but with the upcoming Windows 8 and overlapping Windows 8 Phone release eminent, it’s likely we’ll see a catch-up effect in the App Store.


I dig the Windows Phone platform. And if you get a chance to play with one, give it a shot – it will surprise you.

The real question is whether I will buy a Windows 8 phone or an iPhone 5 when it’s announced in a few months. Depends on what happens in the iPhone space, but it’ll have to be really convincing.  I’m more than willing to try out the next generation of Windows 8 phones.