Inherits: FileConfigReader
Description
The JsonConfigReader class allows you to create a config reader that reads a configuration from a JSON file.
Important points
- The reader supports parameterization using Handlebar template engine.
Configuration parameters
- path: path to the configuration file
- parameters: this entire section is used as template parameters
- …
Constructors
Creates a new instance of the config reader.
public
JsonConfigReader(string path = null)
- path: string - (optional) path to the configuration file.
Instance methods
ReadConfig
Reads a configuration and parameterizes it with given values.
public override
ReadConfig(string correlationId, ConfigParams ConfigParams parameters)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- parameters: ConfigParams - values to parameters the configuration or null to skip parameterization.
- returns: ConfigParams - ConfigParams configuration.
ReadObject
Reads a configuration file, parameterizes its content and converts it into a JSON object.
private
object ReadObject(string correlationId, ConfigParams parameters)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- parameters: ConfigParams - values of the configuration parameters.
- returns: object - JSON object with configuration.
Static methods
ReadConfig
Reads a configuration from a file, parameterizes it with given values and returns a new ConfigParams object.
public static
ConfigParams ReadConfig(string correlationId, string path, ConfigParams parameters)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- path: string - path to configuration file.
- parameters: ConfigParams - values of the configuration parameters.
- returns: ConfigParams - ConfigParams configuration.
ReadObject
Reads a configuration file, parameterizes its content and converts it into a JSON object.
public static
object ReadObject(string correlationId, string path, ConfigParams parameters)
- correlationId: string - (optional) transaction id used to trace execution through the call chain.
- path: string - path to configuration file.
- parameters: ConfigParams - values of the configuration parameters.
- returns: object - JSON object with configuration.
Examples
{ "key1": "{{KEY1_VALUE}}", "key2": "{{KEY2_VALUE}}" }
var configReader = new JsonConfigReader("config.json");
var parameters = ConfigParams.FromTuples("KEY1_VALUE", 123, "KEY2_VALUE", "ABC");
configReader.ReadConfig("123", parameters);