Files
DP44/docs/ai/Common/DTS.Common.Core/Config.md
2026-04-17 14:55:32 -04:00

3.4 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
Common/DTS.Common.Core/Config/DTSConfig.cs
2026-04-17T16:08:08.424741+00:00 zai-org/GLM-5-FP8 1 20e6632b3b560005

Config

Purpose

Provides centralized, thread-safe access to an alternate configuration file for the application. This module exists to allow the system to read settings and configuration sections from a dynamically-specified config file path rather than the default application configuration, supporting scenarios where configuration needs to be externalized or swapped at runtime.

Public Interface

DTSConfig (static class)

  • static void DTSConfigInit(string path) — Initializes the configuration system with the specified config file path. Internally calls SetAltConfigPath.

  • static void AltConfigPathSet(string path) — Thread-safe setter for the alternate config file path. Acquires lock on MyLock before assigning.

  • static string AltConfigPathGet() — Thread-safe getter for the alternate config file path. Acquires lock on MyLock before returning.

  • static void SetAltConfigPath(string path) — Sets the alternate config path and opens the mapped configuration file. If path is null or empty, falls back to DTSConstants.CustomConfigPath. Creates a new Configuration object via ConfigurationManager.OpenMappedExeConfiguration.

  • static Configuration GetAltConfig() — Thread-safe getter returning the current Configuration object for the alternate config file.

  • static string GetAppSetting(string key) — Retrieves an app setting value by key from the alternate configuration. Returns string.Empty if the key is not found (logs a message via APILogger.Log in that case).

  • static object GetSection(string sectionName) — Retrieves a configuration section by name from the alternate configuration. Returns null if the section is not found (logs a message via APILogger.Log in that case).

Invariants

  • All access to static fields (AltConfigPath, AltConfig) is protected by a lock on MyLock for thread safety.
  • SetAltConfigPath must be called before GetAppSetting or GetSection can return meaningful results; otherwise, AltConfig may be null.
  • GetAppSetting always returns a non-null string (empty string if key not found).
  • GetSection may return null if the section does not exist.

Dependencies

Depends on:

  • DTS.Common.Utilities.Logging (uses APILogger.Log)
  • System.Configuration (uses Configuration, ConfigurationManager, ExeConfigurationFileMap, KeyValueConfigurationElement, ConfigurationUserLevel)
  • DTSConstants.CustomConfigPath (referenced constant, defined elsewhere in the codebase)

Dependents: Unknown from source alone.

Gotchas

  • The static constructor is empty, meaning AltConfig is not initialized until SetAltConfigPath is explicitly called. Calling GetAppSetting or GetSection before initialization will result in a NullReferenceException.
  • DTSConfigInit and SetAltConfigPath appear to be redundant; DTSConfigInit simply delegates to SetAltConfigPath with no additional logic.
  • AltConfigPathGet and AltConfigPathSet are separate methods rather than a property, which is unconventional for C#.
  • The GetAppSetting method uses LINQ to cast and search settings, which is less efficient than using the AppSettings.Settings[key] indexer, but handles the case where the key might not exist gracefully.