Instantiating a shared object in a declarative WF4 service... RRS feed

  • Question

  • Hi All,

    I'm trying to integrate the AppFabric cache to my Workflow services and need to create a shared instance of the cache factory object to reuse each time the service is called... I'm also developing the service declaratively (using Receive and SendReply activities) not in C# code; so I'm not writing any hosting code.  Ultimately the service will be hosted in AppFabric.

    My challenge is if I instantiate the object after the Receive activity then it will be instantiated each time the workflow service is called; consequently, several instances of the cache object could exist in persisted instances of the workflow... NOT recommended for the AppFabric cache!

    Instead, I want to have a single instance of the cache object that ALL instances of the workflow service use.

    Any solution or suggestions are greatly appreciated!


    Thanks, KBW
    Wednesday, November 23, 2011 1:34 PM


  • For those trying to solve similar issues with maintaining the instance of a class or object across multiple instances of a workflow... the answer is to create a Singleton and a custom WorkflowServiceHost; instantiating the Singleton in a workflow extension.  You will then have access to those values across all instances of the workflow in question.

    As implied by the reference to WorkflowServiceHost, this assumes the workflow in question is a workflow service.  However, there are similar options for implementing extensions in workflow application.

    Hope this helps!

    Thanks, KBW
    • Proposed as answer by Tim Lovell-Smith Thursday, December 22, 2011 7:47 PM
    • Marked as answer by KWeeks Wednesday, February 1, 2012 2:37 AM
    Thursday, December 22, 2011 1:38 PM