Skip to content

Enable the KeyForFile-Configuration to handle multiple files with the same name but different locations #109588

Open
@ckuetbach

Description

@ckuetbach

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

In our deployments, we use multiple folders for different configuration values.

/var/configs/database1/connectionString
/var/configs/database2/connectionString

The KeyPerFile mechanism seems unable to load data recursively and cannot add a prefix to each key named by a file.

We cannot change some configuration names, such as “connectionString”. If we want to use two different databases, the keys may conflict.

Describe the solution you'd like

I'd like to add a custom prefix to every variable

new ConfigurationBuilder()
    .AddKeyPerFile("/var/configs/database1", optional: true, keyPrefix: "db1:")
    .AddKeyPerFile("/var/configs/database2", optional: true, keyPrefix: "canary:");

Using following file structure:

/var/configs/database1/connectionString
/var/configs/database1/someValue

/var/configs/database2/connectionString
/var/configs/database2/someOtherValue

The configuration will now have following keys:

db1:connectionString
db1:someValue
canary:connectionString
canary:someOtherValue

As an alternative for the same structure above:

new ConfigurationBuilder()
    .AddKeyPerFile("/var/configs", optional: true, recursive: true);

Would lead to following configuration.

database1:connectionString
database1:someValue
database2:connectionString
database2:someOtherValue

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions