Enable binding of IConfiguration/IConfigurationSection#353
Enable binding of IConfiguration/IConfigurationSection#353Kieranties wants to merge 1 commit intoaspnet:devfrom Kieranties:iconfiguration-direct-binding
Conversation
|
Hi @Kieranties, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! TTYL, DNFBOT; |
|
@Kieranties, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
|
This looks correct, but still looks kind of weird to me, @divega thoughts? |
There was a problem hiding this comment.
Can you add one more test where the DerviedOptions that you bind from the first toplevel section, itself has another IConfigurationSection inside of it?
There was a problem hiding this comment.
Sure I'll get this done shortly.
|
Updated with additional tests as requested. /cc @HaoK |
There was a problem hiding this comment.
Nit: I think this could be made slightly simpler if we moved the logic into BindInstance() E.g. at the start it could do:
private static object BindInstance(Type type, object instance, IConfiguration config)
{
if (type == typeof(IConfigurationSection))
{
return config;
}
...Then BindProperty() would remain untouched.
There was a problem hiding this comment.
I'll make this change. It makes it much cleaner :-)
|
@HaoK I think we can take this PR now. I made a comment on a way I think we could simplify it a bit, but no big deal. We could also consider supporting |
|
@divega I did originally have the ability to return |
|
Hrm this feedback sounds familiar :) @divegahttps://github.com/divega I did originally have the ability to return IConfiguration but it seemed unnecessary as IConfigurationSection inherits from there. It also greatly simplifies the type checking. |
|
Any if (type == typeof(IConfigurationSection) || type == typeof(IConfiguration))
{
return config;
} |
|
I like the clear message that when binding you can optionally directly bind child sections as I don't see the benefit in having the type checking as any consumer of the bound property can always treat it as an But hey, you guys are the owners here! I'll happily drop it in if needed ;-) |
|
If I get this merged up with the latest branch is this acceptable or would you like the additional type checking? |
|
@divega are you happy with this PR as is for merging? |
|
I am fine with it as is. |
|
@Kieranties can you rebase and squash your commits into one? I'll merge this after that's done...Thanks! |
|
@HaoK Will get it done this evening |
|
Rebased/Squashed //@HaoK |
|
Merged thanks! |
|
👍 |
Enable binding of
IConfigurationSectionwhen callingConfigurationBinder.Bind()IConfigurationSectionas a unique case when binding a propertyAddresses #274 and aspnet/Options#60