Skip to content

Felipellira/ConfigManager

Repository files navigation

ConfigManager

Overview

The ConfigManager project is a .NET library designed to handle the validation and mapping of intermediate configuration data into strongly-typed configuration objects. It facilitates the conversion of raw configuration data stored in various formats (e.g., dictionaries) into structured objects that adhere to a defined validation schema.

This library ensures that user-defined configurations are validated against defined types, catching invalid or unexpected structures early in the process.

Key Features

  • Validation of intermediate configuration formats against strongly-typed objects.
  • Deep mapping with support for nested, complex data structures.
  • Error handling for unsupported or improperly formatted data (e.g., missing or unexpected fields).
  • Easily extensible to accommodate additional validation rules or mapping requirements.

Core Functionality

  • Validate and Map Dictionaries: Validates configuration dictionaries against a target type and maps the values.
  • Support for Nested Properties: Works with nested objects, handling their validations recursively.
  • Validation of Data Types: Ensures that fields in the configuration data match the expected data types of the target object.
  • Error Handling for Unsupported Configurations: Catches unsupported formats (e.g., list-based configurations).

How It Works

The ConfigManager library functions by abstracting the process of validating and mapping raw configuration data into a structured and strongly-typed object using an intermediate configuration model. The workflow involves the following steps:

  1. Intermediate Configuration Model: The library first parses the raw configuration data into an intermediate format. This intermediate object acts as a generalized abstraction and decouples the validation logic from the source type of the data.

  2. Validation Process: The intermediate configuration object is then validated against a predefined target type (a strongly-typed model defined by the user). During this process, the library ensures that:

    • All required fields in the target type are present in the intermediate configuration.
    • Field types in the intermediate configuration match the expected types defined in the target model.
  3. Error Handling: If the validation process encounters issues, such as missing fields, incorrect data types, or unsupported formats, the library raises appropriate exceptions, allowing the developer to address the problems promptly.

  4. Mapping to Strongly-Typed Object: Upon successful validation, the library maps the values from the intermediate configuration into an instance of the target type. This instance is populated with validated, type-safe configuration data, ready for use in the application.

By isolating the validation and mapping logic via an intermediate representation, the ConfigManager ensures flexibility and reliability, enabling robust configuration management across various data sources.

Installation

Before using the library, ensure your project is compatible with the .NETStandard 2.1 framework. You can include the library in your project as a dependency.

How to Use

  1. Define a strongly-typed model to represent your configuration's structure.
  2. Create an instance of ConfigValidator<T> where T is your strongly-typed model.
  3. Call the Validate method, passing the intermediate configuration object.

Contributions

Contributions to the project are always welcome. If you would like to contribute, please reach out or fork the repository.

This documentation provides a starting guide to understand and quickly integrate ConfigManager into your projects.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages