Skip to main content

Handler implementation

It implements the commands and events defined as extension points in the manifest. Class methods that implement these processes are called command handlersandevent handlers. Implement those handlers as public methods in a public class that implements IExtension (hereafter, main class). The name of the main class and the name of the class file are arbitrary.

Implementation example

Here's an example command handler implementation for the following commands defined in the manifest:

Manifest command definition example

manifest.json
  "extensionPoints": {
"commands": [
{
"id": "Command.SayHello",
"execFunc": "SayHello"
}
],
...
}

In the above command definition example, implement the command handler named SayHello specified in the extensionPoints.commands[0].execFunc property as a public method in the main class.

Implementation example of command handler in main class

MyExtension.cs
//Declaration of namespace of API to be referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;

//main class of the entry point DLL
//Implement IExtension in the main class.
//Handlers are implemented as public methods of this class.
public class MyExtension : IExtension
{
//extension initialization
public void Activate(IContext context)
{
//Implemented as an empty method even if there is no processing
}

//Finalize the extension
public void Deactivate(IContext context)
{
//Implemented as an empty method even if there is no processing
}

//command handler
public void SayHello(ICommandContext context,ICommandParams commandParams)
{
context.App.Window.UI.ShowInformationDialog("Hello !","Hello World");
}

}
  • When using the DLL method, define a class that implements IExtension in the DLL file specified as the entry point. increase.

  • This class implements public methods named Activate, Deactviate.

    Activate method: executed once, just after the extension lifecycle starts.
    Deactivate method: executed once just before the extension lifecycle ends.

Implement as an empty method even if initialization or termination processing is not required.

  • In the Activate and Deactivate methods, you can implement initialization processing and termination processing for the entire extension, apart from processing handlers that are called for each command or event.

    Examples of initialization processing: initialization of common variables, reading of configuration files, etc.
    Examples of termination processing: saving state and settings to a file, etc.

For more information on arguments passed to command handlers, see the following references:

remarks

important

The DLL file specified as the entry point must contain one main class that implements IExtension. All handlers should be implemented as public methods of their main class.

hint

In the case of large-scale extension development, the number of handlers will also increase, so the entry point implementation code will also become bloated. In order to make the entry point implementation code compact, it is recommended to use the following file structure.

  • Split the file by implementing the actual processing in a separate file from the entry point.
  • The handler implemented in the entry point file calls a function implemented in another file or a class method implemented in another class.