public override T Execute <T>(ICommand <T> command)
        {
            var processApplicationIdentifier = ProcessApplicationContextImpl.Get();

            if (processApplicationIdentifier != null)
            {
                // clear the identifier so this interceptor does not apply to nested commands
                ProcessApplicationContextImpl.Clear();

                try
                {
                    var reference = GetPaReference(processApplicationIdentifier);
                    var cmdObj    = command as ICommand <object>;
                    return((T)Context.ExecuteWithinProcessApplication <object>(() => { return Next.Execute(cmdObj); }, reference));
                }
                finally
                {
                    // restore the identifier for subsequent commands
                    ProcessApplicationContextImpl.Set(processApplicationIdentifier);
                }
            }
            return(Next.Execute(command));
        }
 /// <summary>
 ///     Declares the context process application for all subsequent engine API invocations
 ///     until <seealso cref="#clear()" /> is called. The context is bound to the current thread.
 ///     This method should always be used in a try-finally block to ensure that <seealso cref="#clear()" />
 ///     is called under any circumstances.
 /// </summary>
 /// <param name="reference"> a reference to the process application to switch into </param>
 /// <summary>
 ///     Declares the context process application for all subsequent engine API invocations
 ///     until <seealso cref="#clear()" /> is called. The context is bound to the current thread.
 ///     This method should always be used in a try-finally block to ensure that <seealso cref="#clear()" />
 ///     is called under any circumstances.
 /// </summary>
 /// <param name="processApplication"> the process application to switch into </param>
 /// <summary>
 ///     Clears the currently declared context process application.
 /// </summary>
 public static void Clear()
 {
     ProcessApplicationContextImpl.Clear();
 }