I try to uinderstand how method chaining (calling previous or default implementation) works (https://github.com/Microsoft/ConcordExtensibilitySamples/wiki/Component-discovery-and-configuration) but still have many doubts.
DkmExample seems to be dispatcher, but how this class is defined ? Can I define such class ?
Concord interfaces (Microsoft.VisualStudio.Debugger.ComponentInterfaces) do not pass dispatcher in their methods, so how it can be added in implementation ? Do any Concord interface can be chained this way ?
can anyone show how to implement method chaining in https://github.com/microsoft/ConcordExtensibilitySamples/tree/master/HelloWorld/Cs (show how to call default implementation), or provide other real exapmle ?
Thanks in advance
In the Method Chaining Example IDkmExample
represents an interface that is part of the Concord API. This is the interface you, as the developer, are implementing. In the method call itself, DkmExample
is not the dispatcher
but rather a dispatcher object
that the dispatcher knows how to handle. These are defined by the dispatcher and cannot be defined externally.
The method chaining example is there to show that if the implementation does not want to handle the call of the interface method, then it can call the method of the same name on the dispatcher object
(first item in the API method signature), passing in all the parameters that are taken by the method signature minus the dispatcher object itself. This will allow the dispatcher to pass the call, based on filtering and priority, to the next implementation of the interface that it can find.
For a concrete example, we can look at the following block from the Microsoft.VisualStudio.Debugger.Engine.xml
from the microsoft.visualstudio.debugger.engine
nuget package:
<member name="M:Microsoft.VisualStudio.Debugger.ComponentInterfaces.IDkmStartDebuggingOperations.LaunchDebuggedProcess(Microsoft.VisualStudio.Debugger.Start.DkmProcessLaunchRequest)">
<summary>
Causes the debug monitor to create a new process under the debugger. The process
should be left suspended until ResumeDebuggedProcess is called. The debug monitor
must wait for ResumeDebuggedProcess before creating the DkmProcess object since
it needs the UniqueProcessId value from the AD7 Layer.
Note that this method may only be called in response to the Visual Studio
debugger package requesting a launch. Components that wish to launch another
process under the debugger should send a custom event to a visual studio package.
From a package, a launch can be requested through the
IVsDebugger.LaunchDebugTargets API.
</summary>
<param name="request">
[In] DkmProcessLaunchRequest is used to describe the process that debugger should
launch.
</param>
<returns>
[Out] DkmLaunchedProcessInfo is returned from APIs that launch a process.
</returns>
</member>
The interface we are overriding is IDkmStartDebuggingOperations
and the method is LaunchDebuggedProcess
which in the implementation will take a DkmProcessLaunchRequest
, which is a dispatcher object
. If the implementation does not want to handle the call, it can call the next implementation by taking the dispatcher object
and calling the method of the same name on it, passing the necessary parameters.
For example:
internal class MyStartDebuggingOperations : IDkmStartDebuggingOperations
{
public DkmLaunchedProcessInfo LaunchDebuggedProcess(DkmProcessLaunchRequest request)
{
if (/* custom check that this class is to handle it */)
{
// Handle custom implementation here
}
else
{
// This calls the base implementation
return request.LaunchDebuggedProcess();
}
}
}