Friday, November 28, 2008

Unity versus Microsoft Workflow Runtime

Being a true Framework designer I love Inversion Of Control (IOC).

Microsoft's current tool of choise for IOC is Unity.

The other Day, I wanted to use my IOC-container inside the Microsoft Workflow Runtime. The reason for this is that I wanted my custom activities to support IOC;

Although the implementation is straightforward, it might save you some time.

public class UnityDefaultWorkflowSchedulerService: DefaultWorkflowSchedulerService
  private IUnityContainer _container;
  public UnityDefaultWorkflowSchedulerService (IUnityContainer container)
      _container = container;

   protected override void OnStarted()
      //wrap the container in a singleton to make it global

Please note that the example uses the IUnitityContainer directly. However, I like to wrap unity in my own IOC-container thus making the Inversion Of Control Container Inversionable. Get it?

Happy Inversioning.

1 comment:

Matthew said...

What exactly is the 'ServiceLocator' that you are using?