-
Notifications
You must be signed in to change notification settings - Fork 14
Improving AppSettings Processing
The Harmony Core SolutionTemplates include code and sample configuration files for a mechanism that allows environment variables that are required at runtime to be specified via the special appsettings.json file. This mechanism is described in detail in the Environment Variables documentation.
Earlier versions of the solution templates contained code that did not operate as intended, and this document contains instructions on how to alter the supplied code to provide a fully working solution.
To determine if your code needs this fix to be applied, look in your Services.Models project directory and edit the file called AppSettings.dbl. If you look towards the end of that file and find a class named AppEnvironmentVariable
that looks like this:
;;; <summary>
;;; Represents a aingle environment variable.
;;; </summary>
public class AppEnvironmentVariable
;;; <summary>
;;; The name of the environment variable.
;;; </summary>
public readwrite property Name, string
;;; <summary>
;;; The value of the environment variable.
;;; </summary>
public readwrite property Value, string
endclass
Then your code needs updating. If the class is not present then your code has already been fixed.
-
Edit
Services.Models\AppSettings.dbl
and remove the definition of theAppEnvironmentVariable
class (shown above). -
Change the definition of the
EnvironmentVariables
property from this:
public readwrite property EnvironmentVariables, @List<AppEnvironmentVariable>, new List<AppEnvironmentVariable>()
To this
public readwrite property EnvironmentVariables, @Dictionary<string,string>, new Dictionary<string, string>()
- Change the code in the public method
ProcessEnvironmentVariables
from this:
data ev, @AppEnvironmentVariable
foreach ev in EnvironmentVariables
begin
data sts, int
xcall setlog(ev.Name,ev.Value,sts)
end
To this:
data ev, @KeyValuePair<string,string>
foreach ev in EnvironmentVariables
begin
data sts, int
xcall setlog(ev.Key,ev.Value,sts)
end
- Save and close the source file.
- Edit the file
Services.Host\appsettings.json
The file as originally shipped looked like this:
{
"AppSettings": {
"HttpPort": 80,
"HttpsPort": 443,
"EnvironmentVariables": [
{
"Name": "HARMONY_TOKEN_DURATION",
"Value": "1"
},
{
"Name": "HARMONY_LOG_LEVEL",
"Value": "2"
}
]
}
}
The HttpPort
and HttpsPort
settings were never used and can be removed, and the EnvironmentVariables
section must now be changed from being an array of objects with Name
and Value
properties to an array of named string properties.
- Alter the content of the file to look like this:
{
"AppSettings": {
"EnvironmentVariables": {
"HARMONY_TOKEN_DURATION": "1",
"HARMONY_LOG_LEVEL": "2"
}
}
}
If your environment includes configuration files for other environments (e.g. appsettings.Development.json or appsettings.Production.json) then apply similar changes to those files also.
For example, in the sample environment created from the Harmony Core solution templates, you would have a file named appsettings.Development.json
and would need to change this:
{
"AppSettings": {
"HttpPort": 8085,
"HttpsPort": 8086,
"EnvironmentVariables": [
{
"Name": "HARMONY_TOKEN_DURATION",
"Value": "8767"
},
{
"Name": "HARMONY_LOG_LEVEL",
"Value": "6"
}
]
}
}
To this:
{
"AppSettings": {
"EnvironmentVariables": {
"HARMONY_TOKEN_DURATION": "8767",
"HARMONY_LOG_LEVEL": "6"
}
}
}
-
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