Service Configuration
The documentation applies to: v0.8.0
Distributed Systems and Multiple Environments problem¶
In monolithic architecture, this problem isn't complexity. However, in distributed systems, it should be a big challenge to control many configuration files. Combine with multiple environments, it will multiply a number of configuration files for n
environments.
So we need to have a solution for centralizing all configuration files into one place that can provide exactly a environment configuration file.
.NET Core Configuration¶
.NET Core Configuration is a Configuration feature which helps .NET Core serivce to maintain it own configuration file. LET Portal is developed to keep this feature in Service Configuration. Let's take a look in this flow:
- In ServiceA, it has own
appsettings.{env}.json
which containsServiceOptions
andConfigurationServiceOptions
. The main purpose of these options is configuring Service Management's Url, Service Name and Version. Please keep note 3 parameters. - In ServiceA
Program.cs
, ServiceA will take Endpoint, Service Name and Version inappsettings.json
, combine into a url isapi\configurations\ServiceA\v1.0
. For example:http://localhost:56456/api/configurations\ServiceA\v1.0
. - Next, ServiceA performs HTTP GET via this url to retrieve a combined
appsettings.json
file which locates inFiles\ServiceA\v1.0\appsettings.json
folder - In Service Management, it combined
apsettings.json
andappsettings.{Env}.json
which locates in the same folderServiceA\v1.0
. Then it returns this combined file back to ServiceA. - In ServiceA, after retrieving this file, it will combine between local
appsettings.json
and responseappsettings.json
into one. And it will register Configuration Dependency Injection which allowing to useIOptionsMonitor<Options>
.
These files in Files
folder will be look like below:
Merge version-based configuration¶
By default, LET Portal will merge top-bottom based on folder order. For example, if you have this service folder structure:
- ServiceA
- v1.0
- appsettings.json
- appsettings.Prod.json
- v1.1
- appsetting.json
- appsettings.Prod.json
- v1.2
- appsettngs.json
- appsettings.Prod.json
- v1.0
So if you access api/configurations/ServiceA/v1.0
, you will get appsettings.json
of v1.0 only. But if you access api/configurations/ServiceA/v1.2
, you will get combined of v1.0, v1.1, v1.2. Thus, a combined appsettings.json
will be look like
```json tab="v1.0" { "DatabaseOptions": "ABC" }
```json tab="v1.1"
{
"DatabaseOptions": "XYZ",
"Component": "123",
"IsAllowed": true
}
```json tab="v1.2" { "DatabaseOptions": "XYZW", "Component": "ABC" }
```json tab="combined v1.2"
{
"DatabaseOptions": "XYZW",
"Component": "ABC",
"IsAllowed": true
}
Shared Folder¶
Another feature in Service Configuration is shared configuration file. It contains all shared options which applied into all services. The merging rule is applied as service folder.