locked
How to do i call a instance method on static propery? RRS feed

  • Question

  • public static class MyServiceLocator
        {
            public static IServiceLocator Instance
            {
                get
                {
                    lock (_syncLock)
                    {
                        return _instance;
                    }
                }
    
                set
                {
                    lock (_syncLock)
                    {
                        _instance = value;
                    }
                }
            }
    
            private static readonly object _syncLock = new object();
    
            private static IServiceLocator _instance = null;
        }
    
     public interface IServiceLocator
     {
      
             TService GetInstance<TService>();
     }
    

     

    MyServiceLocator.Instance = new UnityServiceLocator()

     


    I  set MyServiceLocator.Instance in global.ascx file. Now, how do i call GetInstance method of IServiceLocator using InvokeMethod activity? 


    • Edited by lax4u Friday, February 3, 2012 8:17 PM
    Friday, February 3, 2012 8:12 PM

Answers

  • TargetObject = name of a variable of type IServiceLocator - or a VB expression which references your public static property on MyServiceLocator or whatver. Basically any way you like to get an InArgument of type IServiceLocator.

    MethodName = GetInstance
    GenericTypeArguments = {TService } [browse for the type]
    Parameters = {} [empty]
    Result = name of a variable of type TService [gets the output]

    Tim


    • Edited by Tim Lovell-Smith Wednesday, February 8, 2012 10:15 PM
    • Proposed as answer by Tim Lovell-Smith Wednesday, February 8, 2012 10:16 PM
    • Marked as answer by LeoTang Sunday, February 12, 2012 2:26 AM
    Wednesday, February 8, 2012 10:14 PM

All replies

  • Hi,

    I think you can define a InArgument in your workflow, pass the MyServiceLocator.Instance directly into workflow via parameters. Then you can call the instance method with or without parameters.

    Using the InvokeMethod Activity

    http://msdn.microsoft.com/en-us/library/dd807388.aspx

    Monday, February 6, 2012 4:59 AM
  • TargetObject = name of a variable of type IServiceLocator - or a VB expression which references your public static property on MyServiceLocator or whatver. Basically any way you like to get an InArgument of type IServiceLocator.

    MethodName = GetInstance
    GenericTypeArguments = {TService } [browse for the type]
    Parameters = {} [empty]
    Result = name of a variable of type TService [gets the output]

    Tim


    • Edited by Tim Lovell-Smith Wednesday, February 8, 2012 10:15 PM
    • Proposed as answer by Tim Lovell-Smith Wednesday, February 8, 2012 10:16 PM
    • Marked as answer by LeoTang Sunday, February 12, 2012 2:26 AM
    Wednesday, February 8, 2012 10:14 PM