-
Notifications
You must be signed in to change notification settings - Fork 14
Tutorial 04 06 Add Main Dispatcher Class
In addition to a routine dispatcher class for each traditional Synergy routine you want to expose, your Traditional Bridge implementation must have a master dispatcher class that registers the individual routine dispatchers with the Traditional Bridge library code, enabling dispatching to these routines as needed.
When we generated code after adding an interface from our Synergy method catalog, a master dispatcher class was created for us. (We'll soon add this class to the solution.) But if you create a Traditional Bridge environment from scratch, you will need to create the master dispatcher. See Generic Code for the Master Dispatcher below, and note that we recommend placing the master dispatcher class in the same folder and namespace as your routine dispatcher classes.
The following is generic code for the master dispatcher class. Like the routine dispatchers, the class inherits from RoutineDispatcher
. Also notice that there is a method for the interface, and for each routine there is a statement that adds the routine's dispatcher to the mDispatchStubs
dictionary. This code includes <interface_name>
and <routine_name>
placeholders, which represent the name of the interface and the name of a traditional Synergy routine:
;;*****************************************************************************
;;
;; Title: <interface_name>Dispatcher.dbl
;;
;; Description: Declares dispatcher classes for exposed methods
;;
;;*****************************************************************************
;; WARNING: GENERATED CODE!
;; This file was generated by CodeGen. Avoid editing the file if possible.
;; Any changes you make will be lost if the file is re-generated.
;;*****************************************************************************
import Harmony.TraditionalBridge
import TraditionalBridge.Dispatchers.<interface_name>
namespace TraditionalBridge.Dispatchers
public partial class <interface_name>Dispatcher extends RoutineDispatcher
public method <interface_name>Dispatcher
proc
;;Declare dispatcher classes for the '<interface_name>' interface methods
mDispatchStubs.Add("<routine_name>", new <routine_name>_Dispatcher())
InitHook()
endmethod
endclass
endnamespace
Notice that the dispatcher method ends with a call to InitHook()
, which is an empty method in the inherited RoutineDispatcher
class. Traditional Synergy does not support partial methods, so this call emulates partial method functionality. It enables you to add logic to the dispatcher method without the risk of losing that code when code is regenerated.
-
In Solution Explorer, right-click the Dispatchers folder (
TraditionalBridge\Sources\Dispatchers
) and selectAdd > Existing Item
from the context menu. -
In the Add Existing Item dialog, navigate to the Dispatchers folder, select
BridgeMethodsDispatcher.dbl
, and then clickAdd
. -
Open the
BridgeMethodsDispatcher.dbl
file, which should look like this:
;;*****************************************************************************
;;
;; Title: <interface_name>Dispatcher.dbl
;;
;; Description: Declares dispatcher classes for exposed methods
;;
;;*****************************************************************************
;; WARNING: GENERATED CODE!
;; This file was generated by CodeGen. Avoid editing the file if possible.
;; Any changes you make will be lost if the file is re-generated.
;;*****************************************************************************
import Harmony.TraditionalBridge
import TraditionalBridge.Dispatchers.<interface_name>
namespace TraditionalBridge.Dispatchers
public partial class <interface_name>Dispatcher extends RoutineDispatcher
public method <interface_name>Dispatcher
proc
;;Declare dispatcher classes for the '<interface_name>' interface methods
mDispatchStubs.Add("AddTwoNumbers", new AddTwoNumbers_Dispatcher())
mDispatchStubs.Add("GetEnvironment", new GetEnvironment_Dispatcher())
mDispatchStubs.Add("GetLogicalName", new GetLogicalName_Dispatcher())
InitHook()
endmethod
endclass
endnamespace
Now we'll use the Harmony Core Upgrade Tool to update all generated code (along with other Traditional Bridge components, as discussed in Updating Traditional Bridge):
-
In Visual Studio, select
Tools > Command Prompt (x64)
to open a command prompt window. -
In Visual Studio, select
File > Close Solution
from the menu to close the Harmony Core solution. -
In the command prompt window, move to your main solution directory and execute the following command:
harmonycore upgrade-latest
You will be required to enter
YES
to confirm the upgrade. -
Close the command prompt, and then open the solution in Visual Studio.
Next topic: Configuring the Traditional Bridge Host Program
-
Tutorial 2: Building a Service from Scratch
- Creating a Basic Solution
- Enabling OData Support
- Configuring Self Hosting
- Entity Collection Endpoints
- API Documentation
- Single Entity Endpoints
- OData Query Support
- Alternate Key Endpoints
- Expanding Relations
- Postman Tests
- Supporting CRUD Operations
- Adding a Primary Key Factory
- Adding Create Endpoints
- Adding Upsert Endpoints
- Adding Patch Endpoints
- Adding Delete Endpoints
-
Harmony Core Code Generator
-
OData Aware Tools
-
Advanced Topics
- CLI Tool Customization
- Adapters
- API Versioning
- Authentication
- Authorization
- Collection Counts
- Customization File
- Custom Field Types
- Custom File Specs
- Custom Properties
- Customizing Generated Code
- Deploying to Linux
- Dynamic Call Protocol
- Environment Variables
- Field Security
- File I/O
- Improving AppSettings Processing
- Logging
- Optimistic Concurrency
- Multi-Tenancy
- Publishing in IIS
- Repeatable Unit Tests
- Stored Procedure Routing
- Suppressing OData Metadata
- Traditional Bridge
- Unit Testing
- EF Core Optimization
- Updating a Harmony Core Solution
- Updating to 3.1.90
- Creating a new Release
-
Background Information