Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Enable binding of IConfiguration/IConfigurationSection#353

Closed
Kieranties wants to merge 1 commit intoaspnet:devfrom
Kieranties:iconfiguration-direct-binding
Closed

Enable binding of IConfiguration/IConfigurationSection#353
Kieranties wants to merge 1 commit intoaspnet:devfrom
Kieranties:iconfiguration-direct-binding

Conversation

@Kieranties
Copy link

Enable binding of IConfigurationSection when calling ConfigurationBinder.Bind()

  • Treats IConfigurationSection as a unique case when binding a property
  • Normal property name -> config section mapping applies

Addresses #274 and aspnet/Options#60

@dnfclas
Copy link

dnfclas commented Dec 14, 2015

Hi @Kieranties, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dnfclas
Copy link

dnfclas commented Dec 14, 2015

@Kieranties, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@HaoK
Copy link
Member

HaoK commented Dec 28, 2015

This looks correct, but still looks kind of weird to me, @divega thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add one more test where the DerviedOptions that you bind from the first toplevel section, itself has another IConfigurationSection inside of it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I'll get this done shortly.

@Kieranties
Copy link
Author

Updated with additional tests as requested. /cc @HaoK

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make this change. It makes it much cleaner :-)

@divega
Copy link

divega commented Jan 15, 2016

@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 IConfiguration as well as IConfigurationSection.

@divega divega assigned HaoK and unassigned divega Jan 15, 2016
@divega divega added this to the 1.0.0-rc2 milestone Jan 15, 2016
@Kieranties
Copy link
Author

@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.

@HaoK
Copy link
Member

HaoK commented Jan 15, 2016

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.

@divega
Copy link

divega commented Jan 15, 2016

Any IConfiguration we will ever try to bind to a property will be an IConfigurationSection so requiring the property to be of that type works. However, if the user defines a property of type IConfiguration and that property doesn't get populated it isn't great. Maybe I am missing something but I am also not sure how supporting IConfiguration would complicate the type checking. Wouldn't be a matter of checking for it too?

if (type == typeof(IConfigurationSection)  || type == typeof(IConfiguration))  
{  
    return config;  
}  

@Kieranties
Copy link
Author

I like the clear message that when binding you can optionally directly bind child sections as IConfigurationSection. That's it, a simple 'bonus' feature to binding logic.

I don't see the benefit in having the type checking as any consumer of the bound property can always treat it as an IConfiguration if they need to, but to the binding logic its just noise.

But hey, you guys are the owners here! I'll happily drop it in if needed ;-)

@Kieranties
Copy link
Author

If I get this merged up with the latest branch is this acceptable or would you like the additional type checking?

@HaoK
Copy link
Member

HaoK commented Feb 22, 2016

@divega are you happy with this PR as is for merging?

@divega
Copy link

divega commented Feb 22, 2016

I am fine with it as is. :shipit:

@HaoK
Copy link
Member

HaoK commented Feb 22, 2016

@Kieranties can you rebase and squash your commits into one? I'll merge this after that's done...Thanks!

@Kieranties
Copy link
Author

@HaoK Will get it done this evening

@Kieranties
Copy link
Author

Rebased/Squashed //@HaoK

@HaoK
Copy link
Member

HaoK commented Feb 24, 2016

Merged thanks!

3480095

@HaoK HaoK closed this Feb 24, 2016
@Kieranties
Copy link
Author

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants