Skip to content

[Microsoft.Testing.Platform] IConfiguration interface is too limited: expose keys or children for custom extensions #5492

@julealgon

Description

@julealgon

Summary

While creating a custom Microsoft.Testing.Platform extension and having to rely on the existing IConfiguration abstraction, we realized that its current public API surface is too restrictive, with only a single indexer for getting a specific key or section as a string.

Because of this limiting API, it is currently not possible to obtain a list of dynamic keys under a given section.

Background and Motivation

While creating a custom extension described in:

We had to rely on hacks to be able to know all possible keys under a json section so that we could then index into each key specifically.

Give the following custom node:

{
  "environmentVariables": {
    "VAR1": "a",
    "VAR2": "b",
    "VAR3": "c",
  }
}

The current indexer API only allows us to make 2 calls:

  1. configuration["environmentVariables"], which returns a raw string with the entire section below it. This would force us to use something like Json deserialization to be useful, completely defeating the purpose of the managed IConfiguration in the first place
  2. configuration["environmentVariables:VAR1"]. Correctly returns the "VAR1" child node, but we have to know that "VAR1" exists beforehand.

Due to this constraint, we were forced to create a hack to adapt our code.

Proposed Feature

The API should either expose all its parsed keys/subkeys, or have a way to navigate into child sections and then get the keys for that section like the Microsoft.Extensions.Configuration IConfiguration allows.

Alternative Designs

This is what we went with:

{
  "environmentVariablesKeys": "VAR1,VAR2,VAR3",
  "environmentVariables": {
    "VAR1": "a",
    "VAR2": "b",
    "VAR3": "c",
  }
}

A new CSV node was added to list all possible keys under the "environmentVariables" section. We then read and parse this entry first, to be able to then specifically index into each key using the syntax specified on 2 above.

This is obviously less than ideal and can lead to consistency problems and unneeded complexity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: MTPBelongs to the Microsoft.Testing.Platform core library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions