Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested list in dictionary property through Autofac.Configuration in JSON are not supported #8

Closed
beachwalker opened this issue Oct 19, 2016 · 2 comments

Comments

@beachwalker
Copy link

beachwalker commented Oct 19, 2016

I use the new model of the Autofac.Configuration but I can't use nested property configuration. The following property NestedListInDictPropThatDoesNotWork is not working:

    "type": "Some.Modules.CoolModule, Some.Modules",
    "properties": {
        "StringProp": "hello world",
        "IntProp": 8090,
        "BoolProp": false,
        "DictProp": { "key": "value" },
        "ListProp": [1, 2, 3, 4, 5],
        "NestedListInDictPropThatDoesNotWork": {
            "myKey": [ "A", "B" ]
        }

Do I have to use an other syntax for that? I want to configure a Dictionary, where the value is a List of items instead of a simple value type.

I also posted this question to stackoverflow.

I use Autofac.Configuration.4.0.1.

@tillig
Copy link
Member

tillig commented Oct 19, 2016

The configuration library isn't doing full "model binding" to figure out property values. It's a much simpler mechanism using a flatter binding concept - much closer to what the classic XML style configuration supported (more "key/value pair" than "recursive binding").

You can see how we parse dictionaries here. It's trying type converters and casting on the value.

To understand why that doesn't "just work," think about how Microsoft.Extensions.Configuration parses this configuration. It's all key/value pairs to that system:

"type" = "Some.Modules.CoolModule, Some.Modules"
"properties:StringProp" = "hello world"
"properties:IntProp" = "8090"
"properties:BoolProp": "false"
"properties:DictProp:key": "value"
"properties:ListProp:0" = "1"
"properties:ListProp:1" = "2"
"properties:ListProp:2" = "3"
"properties:ListProp:3" = "4"
"properties:ListProp:4" = "5"
"properties:NestedListInDictPropThatDoesNotWork:myKey:0" ="A"
"properties:NestedListInDictPropThatDoesNotWork:myKey:1" ="B"

The Autofac configuration stuff does its best to try to "infer" what is meant by each property, but it's not an actual model binder. At the time we originally wrote this, the Microsoft.Configuration.Extensions.Binder stuff wasn't there and when it started getting there, it wasn't quite where we needed it. That may be a better option for us now that .NET Core has settled down a bit.

We'd be happy to take a pull request with an update for this support. In the meantime, I'll mark the issue as an enhancement request.

Also, if you wouldn't mind, in the future try not to cross-post to both the issues list and StackOverflow - try StackOverflow first. Cross-posting the question means we have to cross post the answer and make sure everyone knows where to go for further discussion. It gets confusing. Thanks!

RaymondHuy added a commit to RaymondHuy/Autofac.Configuration that referenced this issue Feb 15, 2020
tillig added a commit that referenced this issue Feb 19, 2020
Enhance Issue #8: Support complex type when configure module
@tillig
Copy link
Member

tillig commented Feb 19, 2020

Resolved by f9e5644 - will release this shortly.

@tillig tillig closed this as completed Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants