Files
2026-04-17 14:55:32 -04:00

4.8 KiB

source_files, generated_at, model, schema_version, sha256
source_files generated_at model schema_version sha256
DataPRO/DataPRO.Core/Config/DataProConfig.cs
2026-04-16T04:27:34.469920+00:00 Qwen/Qwen3-Coder-Next-FP8 1 c18420fbff70f9a1

Config

Documentation: DataProConfig Module


1. Purpose

This module provides centralized, static access to application configuration settings loaded from a custom configuration file (as specified by DataProConstants.CustomConfigPath). It abstracts the underlying ConfigurationManager mechanics to enable consistent retrieval of <appSettings> values and arbitrary configuration sections across the codebase—particularly by plugin code that requires access to non-standard configuration sections. Its existence ensures decoupling from direct ConfigurationManager usage and enforces use of a dedicated configuration file rather than the default app.config/web.config.


2. Public Interface

public static Configuration AltConfig { get; }

  • Type: Static property
  • Behavior: Returns the Configuration object loaded from the custom config file path (DataProConstants.CustomConfigPath). This is the primary handle to the entire configuration structure.
  • Note: The property name AltConfig is misleading—it is not an alternate; it is the primary configuration source for this module.

public static string GetAppSetting(string key)

  • Type: Static method
  • Signature: string GetAppSetting(string key)
  • Behavior: Retrieves the value of an <add key="..." value="..." /> entry from the <appSettings> section of the custom config file. Returns string.Empty if the key is not found.
  • Implementation detail: Uses LINQ over Config.AppSettings.Settings (cast to KeyValueConfigurationElement) to locate the matching key.

public static object GetSection(string sectionName)

  • Type: Static method
  • Signature: object GetSection(string sectionName)
  • Behavior: Retrieves a custom configuration section (e.g., <pluginLibrary>, <dataSources>) by name from the custom config file. Returns null if the section is not defined or fails to load.
  • Intended use: Designed for plugin code to deserialize and consume plugin-specific configuration sections.

3. Invariants

  • The configuration file path is fixed at initialization and derived from DataProConstants.CustomConfigPath.
  • The configuration is loaded once during static initialization (via static constructor) and never reloaded during the application lifetime.
  • GetAppSetting never throws on missing keys—it returns string.Empty.
  • GetSection may return null if the section does not exist or fails to deserialize (e.g., due to schema mismatch), but the source does not indicate explicit error handling or logging.
  • The Configuration object (Config) is opened with openReadOnly: true (third parameter true in OpenMappedExeConfiguration), meaning writes are disallowed.

4. Dependencies

Dependencies on:

  • System.Configuration.ConfigurationManager (for OpenMappedExeConfiguration, GetSection, AppSettings)
  • System.Configuration types: Configuration, ExeConfigurationFileMap, ConfigurationUserLevel, KeyValueConfigurationElement
  • DataProConstants.CustomConfigPath (assumed to be a string constant defining the path to the custom config file)

Dependencies of:

  • Plugin modules (via GetSection) to load plugin-specific configuration.
  • Any code needing access to <appSettings> or custom sections defined in the custom config file.

5. Gotchas

  • Static initialization timing: The config file is loaded at first access to any member of DataProConfig. If DataProConstants.CustomConfigPath points to a non-existent or inaccessible file, the static constructor will throw (e.g., ConfigurationErrorsException), potentially crashing app startup.
  • No fallback behavior: GetAppSetting returns string.Empty for missing keys—callers must explicitly check for this (e.g., string.IsNullOrEmpty) rather than relying on null.
  • No validation: Neither GetAppSetting nor GetSection validates the content or type of returned values. Consumers must handle parsing, casting, and validation themselves.
  • Misleading property name: AltConfig implies it is optional or secondary, but it is the only configuration source used by this module.
  • No thread-safety documentation: While Configuration objects are generally safe for concurrent reads, the source does not explicitly guarantee thread-safety.
  • Assumes <appSettings> structure: GetAppSetting assumes the config file contains a standard <appSettings> section; it does not handle custom section-based key-value storage.

None identified beyond the above.