The Development Harness

The development harness is a simple, but powerful productivity tool. Often developers waste valuable time by working directly in the main application. Every time a developer needs to try out a code modification, they have to build, then run the application, probably login, navigate to the screen they are working on and then see if their feature works correctly. If it doesn’t, they go back, make further code modifications and then build, run, login, navigate again. This is a costly cycle if done over and over again.

The development harness provides a way to directly launch a ViewModel/View with one click. Very little setup is required to get going with the harness and be productive right out of the gate. How does it work? The development harness automatically discovers the ViewModels and renders a button along the left side. When clicking on one of the buttons, the corresponding ViewModel is launched on the right side.

Example screenshot of a Development Harness

image

Bootstrapping

Bootstrapping the harness is very easy. Simply specify the HarnessViewModel as the root type in your bootstrapper. It’s often convenient to have separate projects for the harness and the actual application and share the code between the two projects. This way by switching the Start Project/Start Page one can easily go back and forward between the harness and the application.

using Caliburn.Micro.Extensions;
using DomainModel;

public class AppBootstrapper : FrameworkBootstrapper<HarnessViewModel>
{
}

ViewModel Discovery

ViewModel discovery in the development harness is based on a marker interface. In order for a ViewModel to be discovered by the harness, the ViewModel must implement the IDiscoverableViewModel marker interface.

using IdeaBlade.Application.Framework.Core.ViewModel;

public class CustomerListViewModel : Screen, IDiscoverableViewModel
{
}

ViewModel Setup

Sometimes it is necessary to perform some setup logic before the ViewModel can be launched. For example to setup certain dependencies without which the ViewModel wouldn’t run properly.  To perform this kind of setup logic, the ViewModel can implement the IHarnessAware interface. The interface’s Setup() method will automatically be called before the ViewModel is activated.

using IdeaBlade.Application.Framework.Core.ViewModel;

public class CustomerListViewModel : Screen, IDiscoverableViewModel, IHarnessAware
{
    public void Setup()
    {
        // Perform necessary setup logic
    }
}

Last edited Dec 14, 2011 at 7:03 AM by marcelgood, version 4

Comments

No comments yet.