Showing posts with label Unity. Show all posts
Showing posts with label Unity. Show all posts

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
      ServiceLocator.UseUnityContainer(_container);
      base.OnStarted();
   }
}

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.

Saturday, October 18, 2008

Decorator Pattern using the Unity Framework

Realizing the decorator pattern in the DotNet-Framework has always been easy.

But, with the arrival of the new Unity (Inversion Of Control) Framework setting this up is less intuitive.

Below a config-based example (mainly for my own reference) copied from a codeplex discussion see:

http://www.codeplex.com/unity/Thread/View.aspx?ThreadId=24015


Happy decorating!