MemoryConfigReader

Config reader that stores a configuration in memory.

Inherits: IConfigReader, IReconfigurable

Description

The MemoryConfigReader class allows you to create a config reader that stores a configuration in memory.

Configuration parameters

The configuration parameters are the configuration template

  • path: path to the configuration file
  • parameters: this entire section is used as template parameters

Constructors

Creates a new instance of a config reader.

public MemoryConfigReader(ConfigParams config = null)

  • config: ConfigParams - (optional) component configuration parameters

Fields

_config

protected _config: ConfigParams = new ConfigParams()

Instance methods

AddChangeListener

Adds a listener that will be notified when configuration is changed

public virtual void AddChangeListener(INotifiable listener)

Configure

Configures a component by passing its configuration parameters.

public void Configure(ConfigParams config)

  • config: ConfigParams - configuration parameters to be set.

ReadConfig

Reads a configuration and parameterizes it with given values.

public virtual ConfigParams ReadConfig(string correlationId, 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.

RemoveChangeListener

Remove a previously added change listener.

public virtual void RemoveChangeListener(INotifiable listener)

Examples


var config = ConfigParams.FromTuples(
    "connection.host", "{{SERVICE_HOST}}",
    "connection.port", "{{SERVICE_PORT}}{{^SERVICE_PORT}}8080{{/SERVICE_PORT}}"
);

var configReader = new MemoryConfigReader();
configReader.Configure(config);

var parameters = ConfigParams.fromValue(process.env);
configReader.ReadConfig("123", parameters);