Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

List and Dictionary binding #59

Merged
merged 1 commit into from
Apr 30, 2015
Merged

List and Dictionary binding #59

merged 1 commit into from
Apr 30, 2015

Conversation

victorhurdugaci
Copy link
Contributor

Fixes: #56

  • Support for binding to lists
  • Support for binding to dictionary

Please review: @lodejard @HaoK @glennc

@ghost ghost added the cla-already-signed label Apr 27, 2015
@victorhurdugaci
Copy link
Contributor Author

Btw, Travis and AppVeyor will fail without my changes from Configuration. So don't panic :)

return;
}

VisitType(property.PropertyType, ref propertyValue);
Copy link
Member

Choose a reason for hiding this comment

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

nit: this is really VisitProperty right?

Copy link
Member

Choose a reason for hiding this comment

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

Or more specifically, Read/GetPropertyValue? Is there a reason this method is void with ref object instead of just returning the propertyValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ref is needed because you can have a get only property that was initialized previously and we want to be able to the bindings on that instance. So, it will use the existing instance if it exists, otherwise it creates a new one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could simply return the value but I think it is more explicit to have a ref parameter. It tells you that we can change that value

Copy link
Member

Choose a reason for hiding this comment

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

Why can't you just return the reference to the previous instance or the new instance?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think that is normally understood that objects are mutable. I don't think we typically use ref parameters in general :) It definitely sticks out a bit like a sore thumb... I'd just call it out in a comment for the method if you want to emphasize this point. Making the signature void/ref is overkill (especially since this is a private method)...

@HaoK
Copy link
Member

HaoK commented Apr 27, 2015

Should we consider moving the ConfigurationBinder to configuration itself? For full disclosure, when I asked @lodejard this way back when I first wrote this, his reasoning was having the binding functionality live in options, rather than config nudges people towards options instead of directly binding against configuration...

new ConfigurationBinder(configuration).Read(merge);
}

public void Read(object merge)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps Bind(object instance) would be more clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion

@victorhurdugaci
Copy link
Contributor Author

Updated the PR

Should we consider moving the ConfigurationBinder to configuration itself? For full disclosure, when I asked @lodejard this way back when I first wrote this, his reasoning was having the binding functionality live in options, rather than config nudges people towards options instead of directly binding against configuration...

mmm... maybe? I see the point of having bindings directly in configuration but at the same time having it in options makes sense too. Maybe it would make sense to merge options and configuration completely...

_startConfiguration = configuration;
}

public static void Bind(IConfiguration configuration, object merge)
Copy link
Member

Choose a reason for hiding this comment

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

merge => model?

@victorhurdugaci
Copy link
Contributor Author

Updated


namespace Microsoft.Framework.OptionsModel
{
public class ConfigurationBinder
Copy link
Member

Choose a reason for hiding this comment

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

This whole class pattern is a bit unusual... almost all the methods are static, except for the ctor and one method, and the only field is set once in the ctor and used once in that one method. There don't seem to be any cases where the instance Bind method is called more than once. The runtime doesn't seem to do it, the unit tests don't do it. Is that a scenario?

Copy link
Member

@HaoK HaoK Apr 29, 2015 via email

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I could see potentially being entirely non-static if it helps unit testing, but as it is right now it seems a bit contrived.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to static

- Support for binding to dictionary
@vdangwal
Copy link

vdangwal commented Jun 9, 2016

I am still not sure how to read an Array of objects in program.cs file using IConfigurationRoot or ConfigurationBuilder. Does anyone have example for the same?

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.

None yet

4 participants