locked
IOC / ServiceLocator issues with WorkflowInvoker/WorkflowApplication RRS feed

  • Question

  • Has anyone run into any issues with using an IOC w/ MS ServiceLocator and then later invoking he workflowInvoker or WorkflowApplication?

    Here's the steps that cause problems...

    1. Register services through Castle Windsor IOC
    2. Retrieve a service through the ServiceLocator API
    3. Execute the service I retrieved.
    4. This service then executes an activity/workflow using the WorkflowInvoker.
    5. If I try and retrieve the service through the ServiceLocator again then it fails saying it's unable to find component. 

    The only workaround I've found for this is to run the workflow/activity in a separate app domain and call it via a MarshalByRef proxy.

    When I try and debug this after the WorkflowInvoker runs I can see the services in ServiceLocator are gone. Does WF interact with ServiceLocator during cleanup?

    Monday, June 25, 2012 4:26 PM

Answers

  • Hi Tim,

    I've figured it out... I was re-initializing the IOC with the ServiceLocator a second time from within one of my custom activities. Doh! I'm glad it was something as simple as this.

    Thanks for being so patient. :-)

    • Marked as answer by KinStephen Wednesday, July 11, 2012 7:48 AM
    Wednesday, July 11, 2012 7:48 AM

All replies

  • Hi KinStephen,
    Can I clarify what API you mean by 'MS ServiceLocator'?
    I don't know of any direct usage of Castle Windsor IOC by WorkflowApplication or WorkflowInvoker.
    Is it possible that you are seeing interference with these from another part of your system, such as other custom activities, or custom hosting code?
    Or is it possible that the issue is being confused by WorkflowApplication executing code on a different thread from your main method? (Based on the SynchronizationConext it receives).
    Tim
    Sunday, July 8, 2012 7:44 PM
  • Hi Tim,

    Thanks for replying...  The service locator is the common service locator found on codeplex. http://commonservicelocator.codeplex.com/ It isn't official code shipped as a product from MS but it was written by MS employees and various other people know in the community for IOCs/Frameworks (like SharpArchitecture)/ORMs (like NHibernate) and is now being used in several products like ASP.Net MVC 4.

    Many IOCs like Castle Windsor, Unity, Spring.Net, and MEF for example implement a common interface in the service locator. The purpose of the service locator is to abstract away the IOC your using. Usually you would use the IOCs dependency injection (through the constructor typically), but there are some cases where you need to retrieve a Service by it's interface and that's where the Service Locator comes in. From what I hear even ASP.Net MVC 4 uses this service locator as well.

    You asked if it's possible a custom activity could have caused this to happen... No because I made a test Workflow with nothing in it and it still removed the services held by the IOC (which is accessed through the Service Locator).

    As for the WorkflowApplication being on a separate thread... I tried it through the WorkflowInvoker and had the same results on the same thread. Secondly the ServiceLocator is a singleton and is accessible across threads.

    I hope this clears up the situation for you.

    Thanks again Tim,

    Stephen

    Monday, July 9, 2012 3:22 AM
  • Which exact APIs are you using for these steps?

    1. Register services through Castle Windsor IOC
    2. Retrieve a service through the ServiceLocator API

    Tim

    Tuesday, July 10, 2012 3:35 PM
  • #1 (Registration) happens only once during the initialization of my application (as a windows service/console app).  #2 (Retrieve) is what I'm using during these steps and is called often.
    • Marked as answer by KinStephen Wednesday, July 11, 2012 7:48 AM
    • Unmarked as answer by KinStephen Wednesday, July 11, 2012 7:48 AM
    Tuesday, July 10, 2012 4:34 PM
  • Hi Tim,

    I've figured it out... I was re-initializing the IOC with the ServiceLocator a second time from within one of my custom activities. Doh! I'm glad it was something as simple as this.

    Thanks for being so patient. :-)

    • Marked as answer by KinStephen Wednesday, July 11, 2012 7:48 AM
    Wednesday, July 11, 2012 7:48 AM