-
Notifications
You must be signed in to change notification settings - Fork 14
Tutorial 04 10 Configure Traditional Bridge Environment
All the individual pieces are now in place, and all that remains is to plug some custom code into the service startup pipeline to tell Harmony Core about the Traditional Bridge service and controller that are now available.
We'll provide the necessary custom startup code via a partial implementation of the Services.Startup
class. And if you look in the Services
project, you should already have a file named StartupCustom.dbl
from when you plugged in code related to your Primary Key Generator class in the previous tutorial. You will simply add a little more code to that class.
- Open the
StartupCustom.dbl
file in the Visual Studio editor. (This file is in theServices
project.)
-
Scroll to the bottom of the
ConfigureServicesCustom
method and add the following code immediately before theendmethod
statement.;;---------------------------------------------- ;; Configure the Traditional Bridge environment. data traditionalBridgeDirectory, string data logLevel, string if (_env.IsDevelopment()) then begin traditionalBridgeDirectory=Environment.GetEnvironmentVariable("EXEDIR") if (String.IsNullOrWhiteSpace(traditionalBridgeDirectory)) begin throw new ApplicationException("Logical name EXEDIR is not set. It must point to the TraditionalBridge host application.") end logLevel = "6" end else begin traditionalBridgeDirectory = Path.GetFullPath(Path.GetDirectoryName(^typeof(Startup).Assembly.Location)) logLevel = "2" end
This code specifies the directory where the Traditional Bridge Host application will be executed from, as well as the level of logging that will be performed. Notice that the code uses
_env.IsDevelopment()
, which you won't see defined in the code here. That is because_env
is a class variable that is present in the mainStartup
class. We have access to it because this is aPARTIAL
part of that same class. -
Now add this code immediately below the code you just added:
data launchCommand, string, Path.Combine(traditionalBridgeDirectory,"launch.bat") data environmentVariables, @Dictionary<string,string>,new Dictionary<string,string>(){{"HARMONY_LOG_LEVEL",logLevel}}
This code determines the command that will be used to launch the Traditional Bridge host application on the target system, and it also creates a list of environment variables that will be set within the process used to run the Traditional Bridge host application. It is important to note that there are two ways that the host process can be started. In some cases, Harmony Core will establish an SSH tunnel to a remote target system and send the
launchCommand
to the shell processor on that remote system. In the scenario we are using here, however, Harmony Core will launch a new process on the same machine, and it will instruct that process to execute thelaunchCommand
. -
And add this code immediately below the code you just added:
data contextPool, @ExternalContextPool<BridgeMethodsService>, new ExternalContextPool<BridgeMethodsService> & ( & launchCommand, & "optional_command_parameters", & traditionalBridgeDirectory, & environmentVariables, & 4 & )
This code establishes a context pool (
contextPool
) capable of starting, hosting, allocating, and re-using Traditional Bridge client instances associated with your Traditional Bridge service and environment. -
Finally, add this code immediately below the code you just added:
;; Make 'BridgeMethodsService' available as a DI service services.AddSingleton<IContextFactory<BridgeMethodsService>>(contextPool) services.AddContextPool<BridgeMethodsService>()
This code completes the puzzle. It registers the
contextPool
andTraditionalBridgeService
as services in the dependency injection (DI) container, making them available for use by controllers as needed. -
Save the file.
Before moving on, make sure the project builds:
-
Right-click on the
Services
project and selectBuild
. -
Check the Output window and verify that the build was successful.
Next topic: Testing Traditional Bridge
-
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