Skip to content

Named Options inherit values from parent? #112365

Open
@matthiaslischka

Description

@matthiaslischka

Description

Not sure if that is a bug or just not expected by me, but:
Nested options that I resolve by name have values from the parent set instead of nulls.

Reproduction Steps

Given appsettings like

{
    "MySettings": {
        "SomeValue": "foo1",
        "AnotherValue": "bar1",

        "AnotherMySettings": {
            "SomeValue": "foo2"
        }
    }
}

Register both configs - default and named:

.Configure<MySettings>(null, GetConfiguration().GetSection("MySettings"))
.Configure<MySettings>("AnotherMySettings", GetConfiguration().GetSection("MySettings:AnotherMySettings"))

Resolve AnotherMySettings:

public MyService(IOptionsSnapshot<MySettings> mySettings)
{
    _mySettings = mySettings.Get("AnotherMySettings");
}

Expected behavior

_mySettings.SomeValue = foo2
_mySettings.AnotherValue = null

Actual behavior

_mySettings.SomeValue = foo2
_mySettings.AnotherValue = bar1

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

Demo Project: https://github.com/matthiaslischka/NamedOptions/

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions